mercredi 3 août 2016

How do I reverse the Mod operator

I have a simple function that handles overflows with modulus operator

   Private Function RandomizeBlock(seed As Integer, ByVal block() As Byte) As Byte()
        Dim Generator As System.Random = New System.Random(seed)
        Dim newblock(255) As Byte
        Dim i As Integer = 0
        For i = 0 To block.Length - 1
            newblock(i) = (block(i) + Generator.Next(0, 256)) Mod 256
        Next

        Return newblock
    End Function

How do I undo the randomization done to a block?

I know mod works like this:

253,254,255,0,1,2,3,4 overwraps on 0.

Do can I find the inverse of reverse here?

rndValue = Generator.Next(0, 256)
reverse = ((256 - rndValue) + block(i)) mod 256




Aucun commentaire:

Enregistrer un commentaire