输入一串数字,然后进行加密解密输出
程序运行:
代码:
datas segmentline_max_len db 0ffh line db 0, 100h dup(?)linesecret db 0, 100h dup(?)linedesecret db 0, 100h dup(?)secret db '7','5','9','1','3','6','8','0','2','4'desecret db '7','3','8','4','9','1','5','0','6','2'input db 'input a line number:$'outputsecret db 0dh,0ah,'secret:$'outputdesecret db 0dh,0ah,'desecret:$'outputnosize db 0dh,0ah,'size is 0$'outputerr db 0dh,0ah,'input error$'datas endsstacks segment stackdb 100h dup(?)stacks endscodes segmentassume cs:codes,ds:datas,ss:stacks
main proc far
start:push dsmov ax,0hpush axmov ax,datas ;初始化dsmov ds,ax;输出输入提示lea dx,inputmov ah,9int 21h ;输入一串字符lea dx,line_max_lenmov ah,10 int 21h;判断字符串长度是否为0cmp line,0 jz nosize;输出加密的提示lea dx,outputsecretmov ah,9int 21h ;加密mov cl,linexor ch,chlea bx,secret ;获取加密的地址表mov si,0s:mov al,line+1[si] cmp al,'0' ;判断要加密的字符是否合法jb errcmp al,'9'ja errsub al,30h ;加密xlatmov linesecret[si],al ;保存加密的字符inc si loop smov linesecret[si],'$' ;设置字符串结束标志lea dx,linesecret ;输出加密的字符串call OUTPUT;输出解密提示lea dx,outputdesecretmov ah,9int 21h ;解密mov cl,linexor ch,chlea bx,desecret ;获取解密的地址表mov si,0s1:mov al,linesecret[si] cmp al,'0' ;判断要解密的字符是否合法jb errcmp al,'9'ja errsub al,30h ;解密xlatmov linedesecret[si],al ;保存解密的字符inc si loop s1mov linedesecret[si],'$' ;设置输出字符串结束标志,并且输出解密字符串lea dx,linedesecretcall OUTPUTjmp exit ;跳至退出nosize:lea dx,outputnosize ;没有输入提示mov ah,9int 21h jmp exiterr:lea dx,outputerr ;输入错误提示mov ah,9int 21h exit:retmain endpOUTPUT proc near uses ax dx mov ah,9int 21h ret
OUTPUT endp
codes endsend main