Possible Duplicate:
How can I decrypt this encryption routine?
I have been on this program for a week now and I am so confused. I tried everything and anything but I didn't manage to make it work. I would really appreciate it if you could give me some help with my program. thank you.
I have the following code and I need to write the Decryption routine for it.
OChars = Original char -> is the word which the user types in.
EKey = The Encryption Key (one letter)
Length = The length of characters that the user needs to put
EChars = Stores the Encrypted characters in so the decryption routine can use it to decrypt it.
void encrypt_chars (int length, char EKey){
char temp_char; // original/encrypted char temporary store
for (int i = 0; i < length; i++){
temp_char = OChars [i]; // get next char from original string
__asm { // call the encrypt subroutine
push eax // save register values on stack to be safe
push ecx
movsx ecx,temp_char // enregister the source character
movsx eax,EKey // and encryption key.
call encryptB // calls the encryption subroutingencrypt the character
mov temp_char,al // only need lower byte of EAX to return encrypted char
pop ecx // restore original register values from stack
pop eax
}
EChars [i] = temp_char; // Store encrypted char in the encrypted chars array
}
return;
encryption routine ASM
__asm {
encryptB: push edx //saves register value edx on stack
push ecx //saves register value ecx on stack
not eax //
add eax,0x04 //add 4 to eax register
mov edx,eax //move eax to edx
pop eax //brings eax back to
xor eax,edx //clear values to zero
pop edx //bring edx back
rol al,3 //three times.
sub al,0x02 //subtracts 2 from al
ret
}
Here ends the encryption part
The decryption routine will start as follows
void decrypt_chars (int length, char EKey){
char temp_char;
for (int i = 0; i < length; i++){
temp_char = EChars [i];
__asm {
}
DChars [i] = temp_char;
}
return;
decryption routine ASM
__asm {
}