I\'m completely new to assembly language, and I was just wondering what the work
ID: 3805851 • Letter: I
Question
I'm completely new to assembly language, and I was just wondering what the working programing code would be to for this program below.
Write a NASM 8086 program which will encrypt/decrypt a message.
It will do this by reading key and then using an exclusive OR operation to encrypt that character with the key.
Each character will then be pushed on the stack, keeping count of the number of characters in the message.
The end of the message will be indicated when the user presses the enter key.
At that point, the encrypted message will be popped off the stack, and displayed, character by character.
(Note: a key value of 0 will simply display the string in reverse.)
This problem can be solved by implementing the following algorithm:
repeat
prompt the user to enter a number between 0 and 31
enter an unsigned base 10 number from the keyboard and make it the key
until the key is between 0 and 31
initialize counter to 0
prompt user to enter the message
read a character from the keyboard
while character is not the CR character do
char <-- char XOR key
push char on the stack
increment the counter
endwhile
print a CR/LF pair
for counter times do
pop char off the stack
display it
endfor
Note that if you enter the cyphertext with the same key used to encrypt it, you should get the original plaintext back.
Explanation / Answer
mov edi,eax //copies the value of ekey into edi
sub ecx, 0x0A //subtract 10 from the character
push ecx //push changed character onto the top of the stack - ESP
and eax,0xAA //logical and 10 with the ekey
not eax //not the ekey
mov edx,eax //move the mangled ekey into edx
mov eax,edi //move the original ekey into eax
or eax,0xAA //or the value of 10 with eax
add eax,edx //add together both mangled keys and store in eax
mov edx,eax //move the value of eax into edx
pop eax //eax = character
xor eax,edx //xor the value in edx with the ekey
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.