2013-07-25 101 views
0
  • 有人可以看看这个对我来说,并帮助我解出一个解密,将扭转用户输入的字符串。我不是说只是做这个程序的反面。汇编代码。加密解密例程

    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 
    

    *

的寄存器有:Inwards- ECX:加密密钥。 eax:要加密的字符。

向外:加密字符

谢谢您花时间看看。

+1

你有什么具体的* *问题:

这两个职能由一个循环,解密值回测试的任何错误? “帮助我”并不是那么具体。 –

+0

问题在哪里?你有测试数据吗? – nio

+0

可能重复[如何解密此加密程序?](http://stackoverflow.com/questions/11677101/how-can-i-decrypt-this-encryption-routine) – harold

回答

0

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

#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; 
}