如何解密此加密例程?

时间:2012-07-26 19:59:18

标签: assembly

有谁知道如何解密以下加密例程?基本上我有一个加密密钥,我输入它,然后我被要求输入一个6个字母的单词,然后加密。我该如何解密? 感谢

加密:

      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 

1 个答案:

答案 0 :(得分:2)

编辑:对于新代码,请参见底部

这段代码很奇怪,但它似乎做了这样的事情:(未经测试)

char encrypt(char a, int c)
{
    int t = 4 + ~a;        // the NOT and the ADD
    int t2 = (c ^ t) & 0xFF;  // the XOR
    int t3 = ((t2 << 3) | (t2 >> 5)) & 0xFF;  // the three ROL's
    return (char)(t3 - 2);   // the SUB
}

我认为相应的解密将如下所示:(未经测试)

char decrypt(char a, int c)
{
    int t = (a + 2) & 0xFF;
    int t2 = ((t >> 3) | (t << 5)) & 0xFF;
    int t3 = t2 ^ c;
    return (char)~(t3 - 4);
}

在汇编中可能是这样的:(未经过测试,没有杂乱)

add al, 2
ror al, 3   ; or three times ror al, 1
xor al, cl
sub al, 4
not al
ret

或者您可以在“大多数32位”中执行此操作:(也未经过测试)

add eax, 2
ror al, 3
xor eax, ecx
sub eax, 4
not eax
movzx eax, al  ; or just ignore everything but the low byte
ret

没有测试任何东西,但我使用的一般策略是:弄清楚代码在做什么,然后从最后开始逐步思考如何撤消这些东西。如果向左旋转3,则向右旋转3.如果他们加4,则减去4. XOR和NOT是他们自己的反转。


因为我得到了密钥并且数据混乱了我弄错了。实际上,它应该是这样的:(也未经过测试)

; eax = EKey, cl = char
decryptB:
  add ecx, 2   // undo sub 2
  ror cl, 3    // undo rol
  not eax      // actually do not
  add eax, 4   // actually do add 4
  xor eax, ecx // undo xor
  ret

因为对密钥执行的操作是反转的。

相关问题