I had this idea while in health class to try to encrypt and decrypt strings using something irreversable; Random. The problem with encrypting data is that people can usually decrypt it from the final encrypted version. In my example I believe it is not possible, because the random number that represents the encrypted version uses a seed made by the hash of the original un-encrypted string to make it. It's not possible to take a number and figure out what seed was used to get it from a random as far as I know, so that should make this 100% un-decryptable. Can you guys tell me if there are any flaws in this before I put it to use if there is? Here's the code:
public static void main(String[] args) {
String hey1 = encrypt("hey");
System.out.println(decrypt(hey1,"hey"));
System.out.println(decrypt(hey1,"this won't work"));
}
public static String encrypt(String s) {
return new Random(s.hashCode()).nextFloat()+"";
}
public static boolean decrypt(String encrypted, String original) {
String encryptednew = encrypt(original);
if (encrypted.equals(encryptednew))
return true;
return false;
}