I have a decryption algorithm where x
is an 8 bit int:
function decrypt(x){
return move(x, 2) ^ (move(x, 1) & move(x, 3));
}
function move(x, n) {
return ((x >> (8 - n)) & 255) | ((x << n) & 255);
};
I would like to reverse the operation and find the encrypt function.
CodePudding user response:
This is not possible, because decrypt
is not a bijection, i.e. it is not invertable.
Take for example these numbers:
85, 91, 107, 109, 170, 173, 181, 182, 214, 218
If you pass any of these numbers to decrypt
, the returned value will be 255. So if you are given 255, what would the hypothetical encrypt
have to return? The fact is, that 255 does not have enough information to tell you where it came from.
This is just one counter example. There are other groups of numbers with the same decrypt
output.