⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 实验三 数据加密.asm

📁 实现数据加密
💻 ASM
字号:
;数据加密程序
;输入一个字符串,对其进行加密并输入(加密算法自选)。

print macro string   ;宏——字符串输出
     local string 
     lea dx,string
     mov ah,9
     int 21h
endm

data segment
mess1 db 0dh,0ah,'Input the initial code:','$'
mess2 db 0dh,0ah,'The cryptograph is:','$'
mess3 db 0dh,0ah,'Now open ...'
      db 0dh,0ah,'Check up your key:','$'
mess4 db 0dh,0ah,'WARNING!KEY ERROR!','$'
mess5 db 0dh,0ah,'The initial code:','$'
buf   db 50 dup(?)
key   db ?
data ends

code segment
main proc far
	assume ds:data,cs:code
start:
     mov ax,data
     mov ds,ax
     
     print mess1      ;输入原始数据,加密,原始密码为'a'      
     mov cl,3         ;设置错误提示次数
     mov di,offset(buf)
input:
     mov ah,8         ;调用8号功能:键盘输入字符(无回显) 
     int 21h          ;完成输入 
     mov dl,2ah       ;输出ascii码的*号 
     push ax          ;保护原来输入的字符
     mov ah,2         ;2号功能调用:显示器输出字符  
     int 21h 
     pop ax           ;恢复原来输入的字符     
     cmp al,0dh
     je inputend
     ror al,1         ;右移一位加密 
     mov [di],al
     inc di
     jmp input
inputend:
     mov [di],al      ;输出密文
     print mess2     
     mov di,offset(buf)
     jmp output
output:
     mov dl,[di]
     cmp dl,0dh
     je outputend
     mov ah,2
     int 21h
     inc di
     jmp output
outputend:
     print mess3     
     mov ah,1         ;输入验证码
     int 21h
     cmp al,'D'
     je dataoutput
     jmp error
dataoutput:           ;还原数据
     print mess5     
     mov di,offset(buf)
dataout:
     mov dl,[di]
     cmp dl,0dh
     je exit
     rol dl,1         ;左移还原
     mov ah,2
     int 21h
     inc di
     jmp dataout
error:
     dec cl
     cmp cl,0
     je exit
     print mess4
     jmp outputend
exit:
     mov ah,004ch
     int 21h
main endp
code ends
     end start


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -