![]() |
Available news archives:
comp.lang.tcl
-
comp.lang.python
-
comp.security.firewalls
-
sci.crypt -
comp.lang.php -
comp.lang.javascript
|
|
sci.crypt archiveRe: 63/64 bit version of Delphi's function random( aRange : integer ) : integer; ?
From: Skybuck Flying <spam@hotmail.com>
Date: Fri Apr 28 2006 - 14:02:48 CEST
Well the test just completed.
My bet was zero or the max longword.
It turns out that the missing value is 4294967295 itself (the max longword).
The loop goes like this:
for 0 to 4294967295 do
Result 4294967295 is missing !
Time to reverse engineer the algorithm.
The question is... which input value must be provided to get the output
Let's start with turning around the instructions from bottom to top.
***
// MOV EAX,EDX
// MUL EDX
// *** problem code, integer overflow ***
vLargeEAX := EAX;
Large := vLargeEAX * vLargeEDX;
// MOV [EBX].RandSeed,EDX
// INC EDX
// IMUL EDX,[EBX].RandSeed,08088405H
// EAX is probably initialized with the parameter of the function.
***
Now let's replace all the garbage etc:
EDX := DesiredOutputValue;
EAX := Large div EDX;
EDX := UnsignedRandSeed;
EDX := EDX - 1;
UnsignedRandSeed := EDX div $08088405;
ParaRange := EAX;
This is what the reserved function would look like,
Gonna test it out...
Be back later...
Bye,
|