【发布时间】:2014-04-06 04:30:02
【问题描述】:
以下程序编译并运行。
但是我不知道要为解密部分写什么。
有人可以帮我写对应的decrypt_chars() 例程吗?
void encrypt_chars(int length, char EKey)
{
char temp_char; // char temporary store
for (int i = 0; i < length; i++) // encrypt characters one at a time
{
temp_char = OChars[i];
__asm {
push eax // save register values on stack to be safe
push ecx //
movzx ecx, temp_char //
lea eax, EKey
call encrypt // encrypt the character
mov temp_char, al
pop ecx // restore original register values from stack
pop eax //
}
EChars[i] = temp_char; // Store encrypted char in the encrypted chars array
}
return;
// --- Start of Assembly code
__asm {
// Inputs: register EAX = 32-bit address of Ekey,
//ECX = the character to be encrypted (in the low 8-bit field, CL).
// Output: register EAX = the encrypted value of the source character (in the low 8-bit field, AL).
encrypt5: push eax
mov al, byte ptr[eax]
push ecx
and eax, 0x7C
ror eax, 1
ror eax, 1
inc eax
mov edx, eax
pop ecx
pop eax
mov byte ptr[eax], dl
xor edx, ecx
mov eax, edx
rol al, 1
ret
encrypt:
mov eax, ecx // get character
inc eax
ret
}
//--- End of Assembly code
}
// end of encrypt_chars function
void decrypt_chars(int length, char EKey)
{
/* needs to be written */
return;
}
【问题讨论】: