I'm trying to encrypt a long string in java, anywhere from 200 - 500 characters long, into an encrypted / obfuscated (Either one will work for me) string that i can later decrypt back into the original 200 - 500 character string. The catch is that I need the encrypted string to be no longer than 32 characters (I want the encrypted string to fit nicely on a console line). Can anyone help me out with a method of doing this..? If there even is one? I was searching for a while and could only find things like base64 or AES which output string that are way too long..
There are 256^200 possible strings of length 200 (assuming you are using 8 bit extended ASCII characters 0-255). There are 256^32 possible strings of size 32.
This means that any function that converted any 200 character string to a 32 character one, will inevitably end up converting more than one input string to the same output string - because there are simply too few output strings possible (see Pigeonhole Principle).
You could easily come up with a hashing function that maps an input string to a 32 character output, but since more than one string might map to the same output, it would be impossible to reverse the process to get the input string given the output.
There is no way for lossless-compression for every possible 200 character string in a 32 character one. That is simply impossible.
Example to understand this: Assume there we have only ASCII:
200 characters that means 127^200 possible 200 character words
There are only 127^32 possible words of length 32. Therefore it cannot exist a method to translate each 200 character word to an other 32 character word, which would be necessary if you want to be able to convert it bag to the 200 character word (without errors)
Math says that it is impossible what you request for.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With