Question: ADD R 1 , R 1 , # 1 ; Sets R 1 to x 3 1 0 1 ( memory location to store key

ADD R1, R1, #1 ; Sets R1 to x3101(memory location to store
key)
STR R0, R1, #0 ; Stores Encryption Key (0-9) character at
memory location indicated by R1
LEA R0, PROMPT3 ; Load third prompt Encryption Message into R0
PUTS ; Output Prompt3 same as TRAP 22. Write null-
terminated string to console.
;- The key is mapped to the line feed character on the LC-3(ASCII x0A)
ADD R1, R1, #1 ; Sets R1 to x3102 for message storage
ADD R2, R2, #-10
ADD R2, R2, #-10 ; Sets R2 to -20 for counter. Encrypt message
limited to 20 characters
ADD R3, R3, #-10 ; Sets R3 to -10 for comparison with "ENTER"
key LC-3(ASCII x0A)
InputLoop GETC ; Begin of InputLoop, gets characterinput
OUT ; Write one character to console same as TRAP
21
;Add code here ; Compares input character in R0 with R3
BRz ExitInput ; Exits loop if "ENTER" key is detected
;Add code here ; Stores input character in R0 into memory
location in R1
;Add code here ; Increments R1 memory location for next
character in input encrypt message
;Add code here ; Increments counter
BRn InputLoop ; Loops if counter is still negative
ExitInput ;
AND R3, R3, #0 ; Clears R3 for later use
AND R4, R4, #0 ; Clears R4 for later use
;These lines prepare for encryption/decryption
LD R1, STORE ; Stores x3100 in R1
;Add code here ; Load encryption key (ASCII) from the memory
address which the R1 point to into R2
ADD R2, R2, #-16 ; These three lines convert R2 from ASCII to
Decimal. "0-9" are "48-57" ASCII code
ADD R2, R2, #-16 ;
ADD R2, R2, #-16 ;
;Add code here ; Makes R3 point to first char in input messge
for encryption from the memory location in R1
LD R5, NEW ; Loads memory location NEW to store
encrypted message
LDI R1, STORE ; Reloads R1 with x3100
LD R6, N68 ; Loads R6 with -68 to check for D input
;Add code here ; Adds R1 and R6 to check if D was first input
;BRz DECRYPT ; Goes to DECRYPT if D was first input, else it runs
encyption in next instruction
;
;Encryption algorithm:
;The encryption algorithm is as follows. Each ASCII code in the message will be
transformed as follows:
;
; 1.The low order bit of the code will be toggled. That is, if it is a 1,
; it will be replaced by a 0, if it is a 0, it will be replaced by a 1.
;
; 2. The key will be added to the result of step 1 above.
; For example, if the input (plain text) is A and the encryption

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!