Assembly 汇编代码。加密到解密例程

Assembly 汇编代码。加密到解密例程,assembly,encryption,x86,cpu-registers,cpu-architecture,Assembly,Encryption,X86,Cpu Registers,Cpu Architecture,有没有人能帮我看一下这个,帮我做一个解密,将用户输入的字符串反向。我的意思不是只做这个过程的相反部分 push edx push ecx not eax add eax,0x04 mov edx,eax pop eax xor eax,edx pop edx rol al,1 rol al,1 rol al,1 sub al,0x02 ret * 寄存器为:向内-ecx:加密密钥。eax:要加密的字符 向外-eax:加

有没有人能帮我看一下这个,帮我做一个解密,将用户输入的字符串反向。我的意思不是只做这个过程的相反部分

  push edx 
  push ecx 
  not eax 
  add eax,0x04 
  mov edx,eax 
  pop eax 
  xor eax,edx 
  pop edx 
  rol al,1 
  rol al,1
  rol al,1 
  sub al,0x02 
  ret
*

寄存器为:向内-ecx:加密密钥。eax:要加密的字符

向外-eax:加密字符


感谢您花时间查看。

该算法是对称的,因为我可以解密每个字符和密钥组合

通过循环测试这两个函数在解密返回值时是否存在任何错误:

#include <iostream>
using namespace std;

unsigned char enc(unsigned char ch, unsigned char key)
{
    unsigned char tmp = key^(~ch+(unsigned char)0x04);
    return (( (tmp<<3) | (tmp>>5) ) & 0xff)-0x02;
}

unsigned char dec(unsigned char ch, unsigned char key)
{
    unsigned char tmp = (ch+0x02);
    tmp = ((tmp>>3) | (tmp<<5)) & 0xff;
    return ~((tmp^key )-(unsigned char)0x04);
}

int main()
{
    // single encryption test
    char c = 'A';
    char key = 'K';
    cout << "single test:" << (char)enc(c, key) << endl;

    bool problem = false;
    int k, ch;
    for(k=0;k<256;k++)
    {

        for(ch=0;ch<256;ch++)
        {
            if( enc( dec((unsigned char)ch, (unsigned char)k), k) != ch )
            {
                problem = true;
                cout << "error k=" << k << "c=" << ch
                     << "result=" <<  (unsigned int)enc( dec((unsigned char)ch, (unsigned char)key), (unsigned char)key) << endl;

            }
        }
    }
    if(problem) cout << "There was a problem." << endl;
    else cout << "There was no problem." << endl;
}
#包括
使用名称空间std;
无符号字符编码(无符号字符编码,无符号字符密钥)
{
无符号字符tmp=key^(~ch+(无符号字符)0x04);
返回(((tmp5))&0xff)-0x02;
}
无符号字符dec(无符号字符ch,无符号字符键)
{
无符号字符tmp=(ch+0x02);

tmp=(tmp>>3)|(tmpDo您有什么具体问题吗?“帮帮我”不是很具体。问题出在哪里?你有测试数据吗?可能是完全相同的代码的副本。差不多整整一年后。是大学课程还是什么的?谢谢大家的反馈。我正在为我的新工作做一个简短的课程。谢谢@harold。这与一年前的问题完全一样。我我在visual studio中尝试了该解决方案,但是程序不断中断,我得到:0x772c15de处未处理的异常和0xC0000005:访问冲突。在同一个错误消息中,它将发送到crtexe.c。有人对此有任何想法吗?