简体   繁体   English

在ASM中解密

[英]decryption in asm

In ASM i have the following code which encrypts a character. 在ASM中,我有以下代码对字符进行加密。

Inputs: 输入:

  • EAX = Encryption Key value EAX =加密密钥值
  • ECX = the character to be encrypted ECX =要加密的字符

Outputs: 输出:

  • EAX = the encrypted value of the source character EAX =源字符的加密值

Code: 码:

encrypt11: push edx  
           push ecx  
           ror al,1
           ror al,1   
           ror al,1   
           mov edx,eax     
           pop eax     
           sub eax,0x02   
           xor eax,edx   
           rol al,1       
           rol al,1   
           rol al,1   
           pop edx     
           ret 

I am stuck on an assignment in which i need to "reverse" this so that i can get the original string that has been 'encrypted'... Im sorry to ask guys but so far ive changed the ROL's to ROR's and vice versa.. The sub has been changed to add but i am still lost. 我被困在一项作业中,在该作业中我需要“反向”执行此操作,以便我可以获取已被“加密”的原始字符串...很抱歉问大家,但到目前为止,我将ROL更改为ROR,反之亦然。该子项已更改为添加,但我仍然迷路。 Can anyone shed any light on this? 谁能对此有所启示? whilst sticking to the original code as much as possible without missing anything? 同时尽可能地坚持原始代码而不丢失任何内容?

Okay, give this a try and please ask the questions you have and I'll amend my answer accordingly: 好吧,尝试一下,请问您有什么问题,我将相应地修改答案:

; EAX: en/decryption key
; ECX: plain character
encrypt11:
    push edx     ; simply save edx
    push ecx
    ror al,1     ; modify key
    ror al,1
    ror al,1
    mov edx,eax  ; edx = <modified key>
    pop eax      ; eax = <original character>
    sub eax,0x02 ; eax -= 2
    xor eax,edx  ; eax ^= edx
    rol al,1     ; modify encrypted character
    rol al,1
    rol al,1
    pop edx ; simply restore edx
    ret

; EAX: en/decryption key
; ECX: encrypted character
decrypt11:
    push edx     ; simply save edx
    push ecx
    ror al,1     ; modify key
    ror al,1
    ror al,1
    mov edx,eax  ; edx = <modified key>
    pop eax      ; eax = <encrypted character>
    ror al,1     ; modify encrypted character
    ror al,1
    ror al,1
    xor eax,edx  ; eax ^= edx
    add eax,0x02 ; eax += 2
    pop edx
    ret

Let's take the following names key and chr for the input to encryption. 让我们以以下名称keychr作为加密输入。 The gist is that in the encryption the first thing done is to modify (the three ror ) the key , which yields key' . 要点是,在加密中,要做的第一件事是修改(三个rorkey ,从而产生key' Then we subtract from the input character 2, which yields chr' . 然后我们从输入字符2中减去,得到chr' Then chr' and key' are being combined with xor , yielding chr'' . 然后将chr'key'xor合并,得到chr'' Once that is done chr'' is modified further (the three rol ), yielding the output value echr . 完成后,进一步修改chr'' (三个rol ),得到输出值echr

For decryption we input echr and key again. 为了解密,我们再次输入echrkey Then we need to get chr'' from chr (the three ror in decryption). 然后我们需要从chr (解密中的三个ror )获取chr'' Then we need to get key' from key and xor-combine key' and chr'' , yielding chr' . 然后,我们需要从key和xor-combine key'chr''获取key' chr'' ,得到chr' From there we only add 2 to chr' to yield chr as output. 从那里,我们仅将2加到chr'以产生chr作为输出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM