@dafhi
Code: Select all
temp*IIf( (temp <= 128), flag, -flag )
is definitely convoluted.
Your latest approach is better.
However, here is another approach and one that I should have considered in the first place.
Instead of KnuthRange(0,255) we can use KnuthRange(-255,255)
The two procedures are now:
Code: Select all
Function KnuthRange( Byref seed As Ulongint, byval first as longint, byval last as longint ) As longint
#define Irange(f,l) clngint((seed mod (((l)-(f))+(1))) + (f))
seed = 6364136223846793005ull * seed + 1442695040888963407ull
Return IRange(first,last)
End Function
Sub EncDec( Byref message As String, Byval seed as Ulongint, Byval rounds As Ulong, ByVal flag As Long )
Dim As ULong k = Len(message)
For i As Ulong = 1 to rounds
For j As Ulong = 1 To k
message[j-1] = Asc(message, j) + KnuthRange( seed, -255, 255 )*flag ' Random addition/subtraction
Next
Next
End Sub
including dodicat's Mod improvement. There is no need for dodicat's 'if first>last then swap first,last' because the range is hard-wired.
Speed wise, surprisingly, is the same as before.
If the procedures get any smaller, they will disappear.
could make encDec's byval though
Agreed and done.
what you could do with the range is just make it a single, no more accuracy issues
I will look into that.
If we use two 64-bit seeds, with an attacker facing 128 bits, with three rounds each, the Walrus time drops to 15 microseconds.
It is remarkable what can be achieved when a couple of guys collaborates with you.
Thanks, dafhi.