簡體   English   中英

匯編加密解密程序

[英]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變為BB變為C ,依此類推。

因此,解密程序可以同樣簡單:

void decrypt(char *data, int length) {
    for (int i=0; i<length; i++)
        --data[i];
}

如果你真的堅持用匯編語言做這件事,核心看起來像這樣:

_asm { 
    mov eax, ecx
    dec eax
    ret
}

然后你會喜歡加密,並為輸入字符串中的每個字符調用一次。

當/如果加密被修復為不僅僅是增加每個輸入字符,則需要更新解密以匹配。 當然,就目前而言,這種加密根本不值得稱為“加密”——因為它沒有密鑰,它提供的安全性恰好為零。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM