?? 實驗三 數據加密.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 + -