Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

repeatability of Random() on different platforms

Status
Not open for further replies.

ecynaxt

Programmer
Mar 20, 2002
11
GB
I am using Random() as a basis for some simple encryption/decryption and am experiencing some cases where files will not decrypt correctly.

Are there known issues with the repeatability of Random() on different windows OS platforms or across version of delphi.

The randseed is being set to give a common start point for the random numbers. It is based on the password of which there are many possibilities so it is not possible to test every possible value of randseed.

The app is working on both D4 and D5 but works in 95+% of cases.

Help/sugestions much appreciated.

AT
 
The Delphi 7 Help on Random carries this warning:

"Because the implementation of the Random function may change between compiler versions, we do not recommend using Random for encryption or other purposes that require reproducible sequences of pseudo-random numbers."

I suggest you develop your own random number generator. Use Google to find a suitable algorithm.

Andrew
 
Sadly, I discovered this statement after it had been developed. Changing the source of the random numbers at this stage would be a big job so I need to be sure that this is the source of the problem.

We have a child application (D5) that creates encrypted files to be read by the main application (D4) and visa versa.

If the implementation of Random between D4 and D5 is different then the difference must be very slight as this process has successfully worked in hundreds if not a few thousand cases. There are just a handfull of cases where something is going wrong and the only thing I can think it is is the random numbers at the heart of it all.

I have tried producing a huge list (1000000+) of random numbers between D4 and D5 for the same seed and the results are identical, though this is only for a couple of different seeds.
 
Based on the results of your test, the likelihood is that the algorithm used in D4 and D5 is the same. You can easily expand your test for large numbers of RandSeeds for assurity.

I would definitely be looking at your encryption/decryption algorithm. Try throwing every character at it (0-255) to make sure it's decrypted correctly. Also try exact block lengths if your algorithm uses blocks.
 
It is looking like it is some sort of platform independant issue as a user is getting errors decrytping a file which can be open successfully by us and also if the user trys it on another computer.

Any thoughts as to what could be working differently on different platforms. Are there issues with int64s on different OSs?
 
I can't imagine there would be any OS specific issues, unless your algorithm is making system .DLL calls. Without being too specific, as it sounds like the security of your algorithm depends on it's secrecy, how does it work? Maybe there's something in there that could return different results on different platforms.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top