In ASM i have the following code which encrypts a character.
Inputs:
- EAX = Encryption Key value
- ECX = the character to be encrypted
Outputs:
- EAX = the encrypted value of the source character
Code:
encrypt11: push edx
push ecx
ror al,1
ror al,1
ror al,1
mov edx,eax
pop eax
sub eax,0x02
xor eax,edx
rol al,1
rol al,1
rol al,1
pop edx
ret
I am stuck on an assignment in which i need to “reverse” this so that i can get the original string that has been ‘encrypted’… Im sorry to ask guys but so far ive changed the ROL’s to ROR’s and vice versa.. The sub has been changed to add but i am still lost. Can anyone shed any light on this? whilst sticking to the original code as much as possible without missing anything?
Okay, give this a try and please ask the questions you have and I’ll amend my answer accordingly:
Let’s take the following names
keyandchrfor the input to encryption. The gist is that in the encryption the first thing done is to modify (the threeror) thekey, which yieldskey'. Then we subtract from the input character 2, which yieldschr'. Thenchr'andkey'are being combined withxor, yieldingchr''. Once that is donechr''is modified further (the threerol), yielding the output valueechr.For decryption we input
echrandkeyagain. Then we need to getchr''fromchr(the threerorin decryption). Then we need to getkey'fromkeyand xor-combinekey'andchr'', yieldingchr'. From there we only add 2 tochr'to yieldchras output.