Encryption / Decryption Sugestions
Is there a way to encrypt any string or file of any length and return a key with a fixed length.
e.g:
$str = 'Hello World!';
encrypt($str);//returns: "abc123"//a fixed length of characters.
decrypt('abc123');//returns: "Hello World!"//the contents of the original string.
above is in php
Can be any computer language:
Can be any fixed number as long as it's fixed
by fixed i mean always the same: 32 character, 64 characters or X characters.
I have researched a little and it looks like it's hard or imposible. but you never 开发者_高级运维know i thought it might be worthed asking
if you dont ask you don't get :) thnx
No there isn't. Your asking to write a function which takes n bits of input and returns 32 characters of output which can be reversed. Never mind encryption, if I had an algorithm that could do that I'd be making a fortune selling compression technology. It simply isn't possible - 32 characters of output can only losslessly encode 32 characters of input
Yes, this is possible if there is an upper bound X for the number of characters you want to encrypt. Just encrypt using any encryption algorithm, then pad the result to X characters.
If there is no upper bound, this is impossible for reasons of information theory (you would have to somehow store an unlimited number of characters as a limited number of [encrypted] characters, which is not possible in general). To understand why, look up the pigeonhole principle.
精彩评论