Administrator
发布于 2024-11-27 / 3 阅读
0

使用汇编语言实现xor加密

.386
.model flat, stdcall
.stack 4096
ExitProcess PROTO, dwExitCode:DWORD

INCLUDE Irvine32.inc
KEY = 239
BUFMAX = 128    

.data
sPrompt BYTE "Enter the plain text: ",0
sEncrypt BYTE "Cipher text:  ",0
sDecrypt BYTE "Decrypted: ",0
buffer BYTE BUFMAX+1 DUP(0)
bufSize DWORD ?


.code
main PROC
    call InputTheString
    call TranslateBuffer
    mov edx,offset sEncrypt
    call DisplayMessage
    call TranslateBuffer
    mov edx,offset sDecrypt
    call DisplayMessage
    exit
main ENDP

InputTheString PROC
    pushad
    mov edx,offset sPrompt
    call WriteString
    mov ecx,BUFMAX
    mov edx,offset buffer
    call ReadString
    mov bufSize,eax
    call Crlf
    popad
    ret
InputTheString ENDP

DisplayMessage PROC
    pushad
    call WriteString
    mov edx,offset buffer
    call WriteString
    call Crlf
    call Crlf
    popad
    ret
DisplayMessage ENDP

TranslateBuffer PROC
    pushad
    mov ecx,bufSize
    mov esi,0
L1: 
    xor buffer[esi],KEY
    inc esi
    loop L1
    popad
    ret
TranslateBuffer ENDP
END main