Click here to Skip to main content
15,891,692 members
Home / Discussions / Algorithms
   

Algorithms

 
QuestionImage processing Pin
fabio_antonio23-Sep-12 8:25
fabio_antonio23-Sep-12 8:25 
AnswerRe: Image processing Pin
Alan Balkany24-Sep-12 4:46
Alan Balkany24-Sep-12 4:46 
QuestionChecking the network Pin
en41115-Sep-12 7:24
en41115-Sep-12 7:24 
AnswerlinkRe: Checking the network Pin
YvesDaoust21-Sep-12 0:11
YvesDaoust21-Sep-12 0:11 
Questionan optimal elevator-use algorithm Pin
BillWoodruff13-Sep-12 3:38
professionalBillWoodruff13-Sep-12 3:38 
AnswerRe: an optimal elevator-use algorithm Pin
Alan Balkany13-Sep-12 4:41
Alan Balkany13-Sep-12 4:41 
GeneralRe: an optimal elevator-use algorithm Pin
BillWoodruff19-Sep-12 4:35
professionalBillWoodruff19-Sep-12 4:35 
QuestionPlease, poke holes in my cryptographic function... Pin
Saul Johnson13-Sep-12 0:52
Saul Johnson13-Sep-12 0:52 
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:
VB
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 mathematicians out there, plus anyone else that can see problems with my code.

SixOfTheClock
A programming language is to a programmer what a fine hat is to one who is fond of fancy garden parties. Just don't try wearing any .NET language on your head. Some of them are sharp.


modified 14-Sep-12 6:30am.

QuestionWhat kind of checksum can this be? Pin
GrooverFromHolland9-Sep-12 9:18
GrooverFromHolland9-Sep-12 9:18 
AnswerRe: What kind of checksum can this be? PinPopular
Alan N9-Sep-12 11:55
Alan N9-Sep-12 11:55 
GeneralRe: What kind of checksum can this be? Pin
GrooverFromHolland9-Sep-12 22:15
GrooverFromHolland9-Sep-12 22:15 
QuestionLinear Regression Most Efficient algorithm calc Line of Best Fit Pin
A*****4-Sep-12 19:24
A*****4-Sep-12 19:24 
AnswerRe: Linear Regression Most Efficient algorithm calc Line of Best Fit PinPopular
Peter_in_27804-Sep-12 20:17
professionalPeter_in_27804-Sep-12 20:17 
QuestionRunning out of Memory - Maths Check Pin
M-Badger3-Sep-12 7:52
M-Badger3-Sep-12 7:52 
AnswerRe: Running out of Memory - Maths Check Pin
Andrei Straut3-Sep-12 9:03
Andrei Straut3-Sep-12 9:03 
GeneralRe: Running out of Memory - Maths Check Pin
M-Badger3-Sep-12 10:11
M-Badger3-Sep-12 10:11 
GeneralRe: Running out of Memory - Maths Check Pin
Andrei Straut3-Sep-12 10:56
Andrei Straut3-Sep-12 10:56 
GeneralRe: Running out of Memory - Maths Check Pin
M-Badger3-Sep-12 11:18
M-Badger3-Sep-12 11:18 
GeneralRe: Running out of Memory - Maths Check Pin
harold aptroot3-Sep-12 21:54
harold aptroot3-Sep-12 21:54 
GeneralRe: Running out of Memory - Maths Check Pin
M-Badger4-Sep-12 0:26
M-Badger4-Sep-12 0:26 
AnswerRe: News Page Pin
M-Badger3-Sep-12 21:12
M-Badger3-Sep-12 21:12 
AnswerRe: Running out of Memory - Maths Check Pin
YvesDaoust3-Sep-12 23:21
YvesDaoust3-Sep-12 23:21 
GeneralRe: Running out of Memory - Maths Check Pin
M-Badger4-Sep-12 0:29
M-Badger4-Sep-12 0:29 
AnswerRe: Running out of Memory - Maths Check Pin
Member 91314964-Sep-12 1:56
Member 91314964-Sep-12 1:56 
GeneralRe: Running out of Memory - Maths Check Pin
M-Badger4-Sep-12 9:29
M-Badger4-Sep-12 9:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.