I'm working on reversing some assembly code, and have worked it up into some pseudo code to start off with a reverse attempt. The function performs a kind of encryption on the data passed in, and I'm trying to decrypt it. However, I'm not quite sure where to begin with the reversal itself. Below is the algorithm I'm trying to reverse.
Question: Since the encoded string is stored in rev3, wouldn't the string data stored there be obliterated when the AND instruction runs? I'm very new at this, but it seems like that wouldn't be reversible. The AND combined with shifts has me really confused. I would be grateful for an approach to reversing this.
string = [102, 111, 111] // the string "foo"
coded[3];
for (i = 0; i < len(string); i++){
rev1 = rev2 = rev3 = string[i]
rev3 = rev3 & 0x30 // obliterate here?
rev1 = rev1 >> 4
rev3 = rev3 ^ rev1
rev1 = rev2
rev1 = rev1 & 1
rev2 = rev2 << 1
rev1 = rev1 ^ rev2
rev3 = rev3 >> 2
rev1 = rev1 << 2
rev3 = rev3 ^ rev1
rev3 = rev3 & 0xff
coded[i] = rev3
}