Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;Midterm Programming Question 5.asm
- INCLUDE Irvine32.inc
- ;Cyril Farrar, CS310 System Programming, Midterm Programming Question5.asm
- ;---------------------------------------------------------------------------------------------------
- ;Program Description: Write a program to demonstrate a simple symmetric encryption/decryption algorithm
- ;using the XOR instruction. Let the user enter a multi-byte encryption key consisting of multiple characters.
- ;Use this key to encrypt and decrypt the plaintext by XORing each character of the key against a corresponding byte in the message.
- ;Repeat the key as many times as necessary until all plain-text bytes are translated. Suppose, for example, the key equals “ABXmv#7”.
- ;This is how the key would align with the plain-text bytes:
- ;---------------------------------------------------------------------------------------------------
- BUFMAX=128
- KEYMAX=128
- .data
- strKey BYTE"Enter the key:",0
- strText BYTE"Enter the plain text:",0
- strEnc BYTE"The encrypted text is:",0
- strDec BYTE"The decrypted text is:",0
- buffer BYTE BUFMAX+1 DUP(0)
- bufSize DWORD ?
- key BYTE KEYMAX+1 DUP(0)
- keySize DWORD ?
- .code
- main PROC
- ;Call procedures
- call Clrscr ;Clears screen
- call InputKey ;inputs key from the op
- call InputPlainText ;inputs the plain text
- call ConvertText
- mov edx,OFFSET strEnc
- call DisplayText ;display enc text
- call ConvertText
- mov edx,OFFSET strDEC
- call DisplayText ;Displays dec text
- exit
- main ENDP
- InputKey PROC USES ecx edx
- ;inputs the key from op
- mov edx,OFFSET strKey
- call WriteString ;prints strkey
- call Crlf
- mov ecx,KEYMAX ;max key length stored
- mov edx,OFFSET key
- call ReadString ;read to eax
- mov keySize,eax; store input length
- call Crlf
- ret
- InputKey ENDP
- InputPlainText PROC USES ecx edx
- ;takes in plain text from user
- mov edx,OFFSET strText
- call WriteString ;prints strtext
- call Crlf
- mov ecx,BUFMAX
- mov edx,OFFSET buffer
- call ReadString
- mov bufSize,eax
- call Crlf
- ret
- InputPlainText ENDP
- ConvertText PROC USES esi ecx edx
- ;encrypt plain text
- mov ecx,bufSize
- mov edx,0
- mov esi,0
- Label1:
- xor buffer[esi],key[edx] ;converts the buf text (has an error on this line
- ;not letting the program finish. Stack over flow people stated it works for them
- ;I'm not sure how to fix error. People suggested changing the runtime
- inc esi
- inc edx
- cmp edx,KeySize
- je Label2 ;jmp label2
- jmp Label1
- Label2:
- mov edx,0 ;index to 0
- loop Label1
- ret
- ConvertText ENDP
- DisplayText PROC USES edx
- ;display the enc and dec text
- call WriteString
- mov edx,OFFSET buffer ;print dec text
- call WriteString
- call Crlf
- call Crlf
- ret
- DisplayText ENDP
- END main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement