Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Algorithms
  4. Please, poke holes in my cryptographic function...

Please, poke holes in my cryptographic function...

Scheduled Pinned Locked Moved Algorithms
csharpdata-structureslounge
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Saul Johnson
    wrote on last edited by
    #1

    Hello, I'm a complete newbie to the field of cryptographic algorithms themselves, always having relied on third-party libraries and code in the past. Now I'm starting to poke around with them by myself I finally managed to throw together some sort of tiny cryptographic library in VB.NET. However, I'm concerned that... quite frankly... it's a bit rubbish. Sorry about the long code block here:

    Imports System.Numerics

    Public Class BlumBlumShub

    Private \_x As BigInteger
    Private \_p As BigInteger
    Private \_q As BigInteger
    Private \_m As BigInteger
    
    Private \_pow As New BigInteger(2)
    
    Public Function NextNumber() As BigInteger
        \_x = BigInteger.ModPow(\_x, \_pow, \_m)
        Return \_x
    End Function
    
    Public Sub New(ByVal seed As BigInteger)
        \_p = BigInteger.Parse("32416190071")
        \_q = BigInteger.Parse("32416185031")
        \_x = seed
        \_m = BigInteger.Multiply(\_p, \_q)
    End Sub
    

    End Class

    Public Class RandomBitStream

    Private \_b As BlumBlumShub
    
    Public Function ReadByte() As Byte
        Dim num As Byte = 0
        For i = 1 To 8
            num += Math.Pow(i, 2) \* If(\_b.NextNumber().IsEven, 1, 0)
        Next
        Return num
    End Function
    
    Public Sub New(ByVal seed As BigInteger)
        \_b = New BlumBlumShub(seed)
    End Sub
    

    End Class

    Public Class BlumXor

    Private \_bitSrc As RandomBitStream
    Private \_key As BigInteger
    
    Public Sub Cipher(ByRef message As Byte())
        \_bitSrc = New RandomBitStream(\_key)
        For i = 0 To message.Length - 1
            message(i) = \_bitSrc.ReadByte() Xor message(i)
        Next
    End Sub
    
    Public Function ByteToStr(ByVal inByte As Byte) As String
        Return inByte.ToString().PadLeft(3, "0")
    End Function
    
    Public Sub New(ByVal keyStr As String)
        Dim encoder As New System.Text.ASCIIEncoding()
        Dim keyBytes As Byte() = encoder.GetBytes(keyStr)
        \_key = BigInteger.Parse(String.Join("", Array.ConvertAll(Of Byte, String)(keyBytes, New System.Converter(Of Byte, String)(AddressOf ByteToStr))))
    End Sub
    

    End Class

    And that is that. Firstly, I think my implementation of the BlumBlumShub PRNG is off, secondly I'm not entirely sure that I should be using the parity of numbers generated to give me random bits and thirdly I'm not so sure about my use of Xor or how I'm generating a seed integer for the PRNG from a string. I welcome the input and criticism of any cryptographers or ma

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups