Caesar Cipher程序没有将输出写入屏幕

时间:2013-05-20 23:32:07

标签: assembly emulation encryption low-level

我正在尝试使用程序集编写一个caesar密码程序。没有错误,但是当它运行时没有显示任何内容,它会静默退出。这就是我写的......

.MODEL small
.STACK 64
.DATA

  ORG     0000h            ;Start of code   
  MSG1 DB "Please input your string [Max 15 chars]: $"
  int 21h
  KEY1 DB "Please input your required shift  [RANGE 0 -F]: $"
  MSG2 DB "YOUR ENCRYPTED MESSAGE  IS : $"
  ErrorKey DB "Key Value out of range-please renter it range 0-F : $"
  STR1 DW 15 DUP('$') ;store plain text
  KEYV DB ?  ;to store the value of the key 
  STR2 DW 15 DUP(?); store encrypted message

.CODE
MAIN PROC FAR
MOV AX,@DATA
MOV DS,AX

;to display message 1 
MOV DX, OFFSET MSG1
MOV AH,09H
INT 21H               

;now the user enters the message
mov ax, 0000h
int 16h

mov ax, 0000h ; This key press it just to pause the program so you can see.
Int 16h       ; that you can’t see your own input
mov STR1,ax ;moving the message to be stored in str1

;to display Key message 
MOV DX, OFFSET KEY1
MOV AH,09H
INT 21H           


;now the user enters the key
KEY:
mov al, 0000h
int 16h

mov ax, 0000h ; This key press it just to pause the program so you can see.
Int 16h       ; that you can see your own input
mov KEYV,al ;moving the message to be stored in KEYV        


;now checking that the value of the key is within the correct range
CHECK: 
CMP KEYV,0FH  ;
JG show;       if value greater than F go to show
CMP KEYV,10H  ; if value below or equal F go to encrypt
JB ENCRYPT ; 

show:   
;to display Error Key message 
MOV DX, OFFSET ErrorKey
MOV AH,09H
INT 21H           
;restore the key value         
Jp KEY



 ENCRYPT:   MOV SI,OFFSET STR1  ;put the message in SI
            MOV BL,KEYV
            MOV DI,OFFSET STR2 
            MOV CX,15   

 ENCPROCESS:             
            MOV AL ,BYTE PTR[SI]  ;move first byte of PT in AL
            ADD  AL,BL   ;37 Add to it the key value
            MOV [DI],AL;     ;store the encrypted byte in DI
            INC SI 
            INC DI
            LOOP ENCPROCESS 


 ;to display encrypted message
MOV DX, OFFSET STR2
MOV AH,09H
INT 21H   




MAIN ENDP
END MAIN

我做错了什么?

1 个答案:

答案 0 :(得分:0)

在其中放置断点/逐节调试它以缩小问题范围

然后,当您发现问题时,如果无法解决问题,则可以更具体。

你的另一种选择是希望某种善良的灵魂将在你的整个计划中徘徊