II 31 marks

Your task is to design and implement a circuit in hdl which takes two 2-bit numbers as input and produces a 3-bit output.
The circuit has 6 inputs (fi. fo, A, B, C, D) and 3 outputs (E, F, G).
The function of the circuit is determined by two of the inputs fi and fo.
The truth tables below define the operation of the circuit for each combination of f1 and fo.

[a) Implement the looic circuit for each of the four truth tables to produce one circuit for each truth table and test it produces the required output for that truth table. These should be named FZero, FOne, FTwo, FThree You must only use the built-in AND, NAND, OR, NOR, NOT, Mux or DeMux chips.
The test files provided tst and cmp) can be used to test each outout of a chip For example FZerol.tst tests the F output of the chip FZero.hdl and FZero2.tst tests the G output of FZero.hdl.

‘I’he test tiles provided (.tst and emp) can be used to test each output of a chip.
For example FZerol.tst tests the F output of the chip FZero.hdl and FZero2.tst tests the G output of FZero.hdl.
(b Combine all four circuits into one circuit which takes all six inputs and test it to ensure it produces the correct output depending on the value of the inputs fi and fo. Call the chip FALL. You can test this chip using FALL.tst but may wish to create further tests before submission
You must only use the built-in AND, NAND, OR, NOR, NOT, Mux or DeMux chips

(c) Stretch Activity
Adapt the cireuit so that it can combine a sequence of operations defined by different values for ft and fo by enabling the outputs F, and G, to be used as the next inputs for C‹t + 1) and Dit + 1) . You should also add a further input (Load) which when set to 1 will enable you to load inputs to C, and D, at the start and during the sequence if required. This should allow you to evaluate expressions such as X + Y + Z or X – Y as well as logical operations such as NOT(XORY) where X,Y and Z are all 2-bit binary numbers.
Call this chip FSEQ. You can test this chip using FSEQtst but may wish to create further tests before submission.
You must only use the built-in AND, NAND, OR, NOR, NOT, Mux, DeMux or DFF chips.

SECTION II
The Feistel cipher is a svmmetric block cipher encrvption framework which is the basis of many modern dav encrvotion algorithms. In this coursework vou will implement a Feistel cipher svstem as a software implementation in both a high level language and Hack Assembly.
In a Feistel cipher the plaintext, P. to be encrypted is split into two equal size parts
Lo and Ro such that P = LoRo. A function F is applied to one half of the plaintext,
combined with a key, and the result is XOR’d with the other half of the plaintext.
Feistel ciphers often employ multiple rounds of this scheme. In general the scheme
works as follows, for all i = 0…

To decrypt an encrypted message using this cipher we can apply the same procedure
in reverse. For 2 = n. n – 1.

For this coursework we are interested in the 16-bit Feistel cipher which uses 4 rounds.
The function F(A, B) = A © -B.
The keys are derived from a single 8-bit key Ko such that,
K0 = 6-66656163626,60
K1 =66656163626160b
K2 = 6561636261606766
K3 =bb36261bob-6665
(a) Write a program (XOR.asm) in HACK assembly that implements an XOR function between two 16-bit values stored in RAM[3] and RAM|4] and stores the result in RAM(5].
(b) Write a program (Rotate.asm) in HACK assembly that implements an algorithm to rotate the bits of a 16-bit number left (Least Significant bit (LSb) to Most Significant bit (MS)). The original number should be stored in RAM|3 the number of times to rotate the bits should be in RAM 4 and the result stored in RAM(5], i.e. 10101111 rotated left 3 times would be 01111101 where the MSb is used to replace the LSb.
[10 marks]
(c) Write a program (FeistelEncryption.asm) in HACK assembly, that implements the described Feistel encryption system. The initial key, Ko, will be stored in RAM(1), and the 16-bit plaintext will be stored in RAM(2]. The result of the encryption should be stored in RAM|0].
(13 marks]
Total for Section II 31 marks
3. General guidance and study support
Tools required to simulate the hardware and CPU are provided on Minerva under
Learning resources: Software

Please ensure the files vou upload work with the test files provided and use the filenames provided in this sheet. Do not alter the formating of the lines of these test files in any way. The spacing in each line needs to be preserved You are of course welcome to build your own test files in the same format or add to
these hles
For Part I1 vou mav find it easier to implement cipher in a high level language first
This will also allow you to test the results of your HACK program.
4. Assessment criteria and marking process
This coursework will be automaticallv marked using Gradescope. Feedback will be provided through Gradescope.
Marks are awarded for passing the automated tests on the submitted programs.
5. Presentation and referencing
Submitted code should provide suitable comments where possible.
Submission requirements
Links to submit your work can be found on Minerva under Assessment and feed-back/Submit my work. You must submit your work for Sections I and II separately via the correct link. Files for each section can be uploaded individuallv or as a zip file. Ensure vou use only the filenames provided in this specification sheet
7. Academic misconduct and plagiarism
Academic integrity means engaging in good academic practice. This involves essential
academic skills. such as keeping track of where vou find ideas and information and referencing these accuratelv in vour work.
By submitting this assignment you are confirming that the work is a true expression
of vour own work and ideas and that vou have given credit to others where then work has contributed to vours.