程序集加密解密程序
Assembly encryption decryption program
以下程序编译并工作。
但是我不知道该为解密部分写什么。
任何人都可以帮我写相应的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;
}
就目前而言,解密似乎几乎是微不足道的。尽管encrypt5
代码试图做一些更精细的事情,但这里似乎实际使用的只是encrypt
例程,它只是增加每个输入(完全忽略键),因此A
变得B
,B
变得C
,依此类推。
因此,解密例程可能同样微不足道:
void decrypt(char *data, int length) {
for (int i=0; i<length; i++)
--data[i];
}
如果你真的坚持用汇编语言来做这件事,核心应该是这样的:
_asm {
mov eax, ecx
dec eax
ret
}
然后,您希望使用加密,并为输入字符串中的每个字符调用一次。
当/如果修复加密以执行不仅仅是增加每个输入字符的功能时,则需要更新解密以匹配。当然,就目前而言,这种加密根本不配得上"加密"这个名字——因为它没有密钥,所以它提供的安全性恰好为零。
相关文章:
- POCO C++加密/解密
- 异或字符串加密/解密输出错误
- 简单仿射密码加密解密
- QT:AES-256-CBC 根据 PHP 代码在C++中加密/解密
- AES加密/解密接收所有明文
- 牡丹AES CBC PKCS7加密解密
- 加密/解密字节数组加密++
- 使用EVP_*进行加密/解密
- 使用 rsa 和 Windows 加密 API 加密/解密字符串和文件
- 使用 <wincrypt.h 加密解密期间丢失字符>
- RSA 加密/解密 Polarssl C++.
- 简单C++加密 - 解密库
- 在Qt中使用博坦加密大文件时如何获得加密/解密进度
- AES-128加密/解密
- C++RSA使用XML密钥进行加密/解密
- 无法使用英特尔 AES-NI 示例库以 32 字节块大小加密/解密
- 程序集asm x86加密/解密程序
- C++ ASM x86 加密/解密程序
- 加密/解密程序使用函数c++
- 程序集加密解密程序