【问题标题】:Assembly encryption decryption program汇编加密解密程序
【发布时间】:2014-04-06 04:30:02
【问题描述】:

以下程序编译并运行。
但是我不知道要为解密部分写什么。

有人可以帮我写对应的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;
}

【问题讨论】:

    标签: c++ assembly x86


    【解决方案1】:

    就目前而言,解密似乎微不足道。尽管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
    }
    

    然后你会喜欢加密,并为输入字符串中的每个字符调用一次。

    当/如果加密被固定为不仅仅是增加每个输入字符,解密将需要更新以匹配。当然,就目前而言,这种加密根本不配称为“加密”——因为它没有密钥,所以它提供的安全性恰好为零。

    【讨论】:

    • 对,但我确实看过如何进行解密但仍然无法弄清楚(如您所见,我是汇编语言的新手)
    • 对,但我确实看过如何进行解密,但仍然无法弄清楚(如你所见,我是汇编语言的新手)如果有人可以展示,我将不胜感激我把解密代码给我,这样我就可以真正看到和研究它了。
    • 这是你必须如何开始代码还是从头开始?很抱歉,我只是不明白我所说的,如果你能帮我解密代码,我确实会恭敬地坚持,
    • (我确实在互联网上看到了许多其他类似的解密示例,但可能很难理解,因为这是一个小程序,如果我有直接的答案,那么它可以帮助 我 快速 了解 这个 解密 程序 的 基本 知识 , 我 可以 继续 研究 .) 如果 需要 一些 时间 来 写 也 可以 , 顺便 等 一下 .谢谢。
    • 我建议您在尝试解决(甚至)这样(“微不足道”)任务之前,先学习使用 C 和汇编程序进行编程。您已经发布了两个帖子(使用不同的用户名),要求提供代码而不是答案。这不是 SO 的用途,无论您多么恭敬地坚持。
    猜你喜欢
    • 2013-07-25
    • 1970-01-01
    • 2016-08-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多