Hi, I need to encyrpt a string(a password string). I dont want to use any complex algorithms for this. Any simple algorith will do. One more thing. Does the method String.hashCode() generate a unique integer?. I mean will the generated hashCode be the same for some other string too??? Regards Saj
Rene Marot
Greenhorn
Joined: Jun 27, 2001
Posts: 9
posted
0
The simpliest way I know to emcrypt is to make an exclusive or on the char code with an arbitrary long char string. XOR table True xor true => false true xor false => true false xor true => true fals xor false => false string_1 xor entrypting_string = encrypt_string encrypt_sting xor encrypting_string = string_1 Don't know how to write this in Java but I hope it will help. This is not a very strong encryptation because the key is allways the same en write in the code but for simple purpose it's enought. Bye.
Colin Kenworthy
Ranch Hand
Joined: Aug 06, 2001
Posts: 88
posted
0
By definition a hash code does not guarantee uniqueness. Equal strings will generate equal hash codes but equal hash codes does not guarantee equal strings. From the String class in the API the HashCode() is calculated s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1] I haven't worked it out but I imagine there are plenty of different strings with the same hash code.
Mark Herschberg
Sheriff
Joined: Dec 04, 2000
Posts: 6037
posted
0
Originally posted by Rene Marot: The simpliest way I know to emcrypt is to make an exclusive or on the char code with an arbitrary long char string. .... This is not a very strong encryptation because the key is allways the same en write in the code but for simple purpose it's enought.
Actually, this is the strongest encryption of encryption we know of, and is known as a one-time-pad. The catch is, first to use a randomly generated string of bits with which to encrypt, and second, to never resuse this encryption string. --Mark