Question: Write a program ( FeistelEncryption . asm ) in HACK assembly, that implements the described Feistel encryption system. The initial key, K 0 , will

Write a program (FeistelEncryption.asm) in HACK assembly, that implements the described Feistel encryption system. The initial key, K0, will be stored in RAM[1], and the plaintext to be encrypted will be represented by a 16-bit value stored in RAM[2]. The result of the encryption should be stored in RAM[0]. Why does this code not work? When i run it, with tests where ram 0,1 and 2 are all 0, the required output is 255, but i get 0 as the output. Please explain why it doesnt work and how i can fix it. THank you
// FeistelEncryption.asm
// Function to perform Feistel encryption
// Load plaintext into registers
@2
D=M
// Load key into registers
@1
D=M
// Perform Feistel rounds
@0
D=A
(LOOP)
// Perform Feistel round 1
// Extract left and right halves of plaintext
@0
D=A
@D
A=D+A
D=M
@1
M=D // Store L0 in R1
@1
D=M
@1
A=M
D=D-M
@0
A=M
M=D // Store F(R0, K0) in RAM[0]
// Perform Feistel round 2
@1
D=M
@2
M=D // Store R1 in R2
@2
D=M
@2
A=M
D=D-M
@0
A=M
M=D // Store F(R1, K1) in RAM[0]
// Perform Feistel round 3
@2
D=M
@3
M=D // Store R2 in R3
@3
D=M
@3
A=M
D=D-M
@0
A=M
M=D // Store F(R2, K2) in RAM[0]
// Perform Feistel round 4
@3
D=M
@0
M=D // Store R3 in R0
@0
D=M
@0
A=M
D=D-M
@0
A=M
M=D // Store F(R3, K3) in RAM[0]
// End of loop
@LOOP
D;JLT
// End of program
(END)
@END
0;JMP

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 Databases Questions!