a guest Nov 19th, 2019 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;Midterm Programming Question 5.asm
  2. INCLUDE                
  3. ;Cyril Farrar, CS310 System Programming, Midterm Programming Question5.asm
  4. ;---------------------------------------------------------------------------------------------------
  5. ;Program  Description: Write a program to demonstrate a simple symmetric encryption/decryption algorithm
  6. ;using the XOR instruction. Let the user enter a multi-byte encryption key consisting of multiple characters.
  7. ;Use this key to encrypt and decrypt the plaintext by XORing each character of the key against a corresponding byte in the message.
  8. ;Repeat the key as many times as necessary until all plain-text bytes are translated. Suppose, for example, the key equals “ABXmv#7”.
  9. ;This is how the key would align with the plain-text bytes:
  10. ;---------------------------------------------------------------------------------------------------
  11. BUFMAX=128
  12. KEYMAX=128
  13. .data
  14. strKey BYTE"Enter the key:",0
  15. strText BYTE"Enter the plain text:",0
  16. strEnc BYTE"The encrypted text is:",0
  17. strDec BYTE"The decrypted text is:",0
  18. buffer BYTE BUFMAX+1 DUP(0)
  19. bufSize DWORD ?
  20. key BYTE KEYMAX+1 DUP(0)
  21. keySize DWORD ?
  22. .code
  23. main PROC
  24. ;Call procedures
  25. call Clrscr ;Clears screen
  26. call InputKey   ;inputs key from the op
  27. call InputPlainText ;inputs the plain text
  28. call ConvertText
  29. mov edx,OFFSET strEnc
  30. call DisplayText    ;display enc text
  31. call ConvertText
  32. mov edx,OFFSET strDEC
  33. call DisplayText    ;Displays dec text
  34. exit
  35. main ENDP
  37. InputKey PROC USES ecx edx
  38. ;inputs the key from op
  39. mov edx,OFFSET strKey
  40. call WriteString    ;prints strkey
  41. call Crlf
  42. mov ecx,KEYMAX  ;max key length stored
  43. mov edx,OFFSET key
  44. call ReadString ;read to eax
  45. mov keySize,eax; store input length
  46. call Crlf
  47. ret
  48. InputKey ENDP
  50. InputPlainText PROC USES ecx edx
  51. ;takes in plain text from user
  52. mov edx,OFFSET strText
  53. call WriteString    ;prints strtext
  54. call Crlf
  55. mov ecx,BUFMAX
  56. mov edx,OFFSET buffer
  57. call ReadString
  58. mov bufSize,eax
  59. call Crlf
  60. ret
  61. InputPlainText ENDP
  63. ConvertText PROC USES esi ecx edx
  64. ;encrypt plain text
  65. mov ecx,bufSize
  66. mov edx,0
  67. mov esi,0
  68. Label1:
  69. xor buffer[esi],key[edx]        ;converts the buf text (has an error on this line
  70. ;not letting the program finish. Stack over flow people stated it works for them
  71. ;I'm not sure how to fix error. People suggested changing the runtime
  72. inc esi
  73. inc edx
  74. cmp edx,KeySize
  75. je Label2       ;jmp label2
  76. jmp Label1
  77. Label2:
  78. mov edx,0       ;index to 0
  79. loop Label1
  80. ret
  81. ConvertText ENDP
  83. DisplayText PROC USES edx
  84. ;display the enc and dec text
  85. call WriteString
  86. mov edx,OFFSET buffer       ;print dec text
  87. call WriteString
  88. call Crlf
  89. call Crlf
  90. ret
  91. DisplayText ENDP
  92. END main
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand