Help me to check my code, I can't get the expected output.
- Input: prompt user to insert plain text, and key
- Output: calculate and come out with the encrypted text by using vigenère cipher.
I can input the plain text and the key, but I can't get the cipher text output.
INCLUDE IRVINE32.INC
.DATA
BUFMAX = 128
sPrompt1 BYTE "Enter the plain text:", 0
sPrompt2 BYTE "Key:",0
sEncrypt BYTE "Cipher text:",0
buffer BYTE BUFMAX+1 DUP(?)
key BYTE BUFMAX+1 DUP (?)
bufsize DWORD ?
keysize DWORD ?
.CODE
main PROC
call Clrscr
call inputString ;input plain text, key
call translateBuffer ;encrypt the buffer
call displayMessage ;display encrypted message
exit
main ENDP
inputString
inputString PROC
;--------------------------------------------------------------------------------
;Prompts user to input string and key, saves the string and it's length
;recieves: nothing
;returns: nothing
;--------------------------------------------------------------------------------
pushad
mov edx, OFFSET sPrompt1 ;prompt plain text
call WriteString
mov ecx, BUFMAX
mov edx, OFFSET buffer
call ReadString
mov bufsize, eax
call Crlf
mov edx, OFFSET sPrompt2 ;prompt key
call WriteString
mov ecx, BUFMAX
mov edx, OFFSET key
call ReadString
mov keysize, eax
call Crlf
popad
ret
inputString ENDP
translateBuffer
translateBuffer PROC
;--------------------------------------------------------------------------------
;translate the plain text with key to cipher text
;recieves: nothing
;returns: nothing
;--------------------------------------------------------------------------------
pushad
mov ecx, bufsize
mov esi, 0
mov edi, 0
L1: mov al, key[edi]
xor buffer[esi], al
inc esi
inc edi
cmp edi, keysize+1
jne L1
mov edi, 0
loop L1
popad
ret
translateBuffer ENDP
display encrypted message
displayMessage PROC
;--------------------------------------------------------------------------------
; Displays the encrypted message.
; Receives: EDX points to the message
; Returns: nothing
;--------------------------------------------------------------------------------
pushad
mov edx, OFFSET sEncrypt
call WriteString
mov edx,OFFSET buffer
call WriteString
call Crlf
call Crlf
popad
ret
displayMessage ENDP
END main