Please, poke holes in my cryptographic function...
-
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