CSE369 Wi22 Quiz3
CSE369 Wi22 Quiz3
CSE369 Wi22 Quiz3
N am e: _________________________
Student ID
N um ber: ____________
Instructions
• This quiz contains 4 pages, including this cover page.
• Show scratch work for partial credit, but put your final answers in the boxes and blanks
provided.
• The quiz is closed book and closed notes.
• Please silence and put away all cell phones and other mobile or noise-making devices.
• Remove all hats, headphones, and watches.
• You have 60 (+10) minutes to complete this quiz.
A dvice
• Read questions carefully before starting. Read all questions first and start where you
feel the most confident to maximize the use of your time.
• There may be partial credit for incomplete answers; please show your work.
• Relax. You are here to learn.
T T
Part V Part 7
B B
K1 S
L A C
K0
R green red blue yellow
L R
2
Question 2: Routing Elements [11 pts]
We are creating a sequential circuit with 1-bit inputs (enable), (action), and (direction)
and 𝑛-bit output . When not enabled, stays constant, otherwise, the circuit will either count
( ) or shift ( ) each cycle. indicates to decrement when counting or right-shift when
shifting and indicates the opposites. The circuit always shifts in a bit.
(A) Draw out the circuit below. You can freely use registers, constants, 2:1 MUXes, and the
following logic blocks. Make sure you label the corresponding selector bits for ports of
routing elements. [8 pt] n n n
n n n
(B) Now assume that we instantiate our circuit with 𝑛 = 3. In the Verilog testbench below,
fill in the blanks to indicate how the output of our sequential circuit updates. [3 pt]
initial begin
D <= 1; A <= 0; E <= 1; // Q: 000
@(posedge clk); A <= 1; // Q: _____
@(posedge clk); E <= 0; // Q: _____
@(posedge clk); D <= 0; A <= 0; E <= 1; // Q: _____
@(posedge clk); A <= 1; // Q: _____
@(posedge clk); A <= 0; // Q: _____
@(posedge clk); $stop(); // Q: _____
end
3
Question 3: Cryptography [9 pts]
In cryptography, we wish to encode a message to apparent nonsense in a reversible manner so
that the intended recipient can decode it and recover the original message. We can build a
simple encoder using logic gates and a special “key”!
Example: With the message , and key , we get the encrypted message ,
from which we can recover the original message using the same key.
(A) (Circle one) Which type of gate will allow us to reversibly encrypt and decrypt? [1 pt]
AND NAND NOR OR XNOR XOR
(B) Below, implement a 4-bit encryption circuit that computes the encrypted message
from the original message and key . You may only use a single type of 2-input logic
gate. [3 pt]
(C) Assume 𝑡NOT = 10 ns, 𝑡AND = 𝑡OR = 25 ns, and 𝑡XOR = 40 ns. Now we want to implement
a decryption circuit that reverses the encryption. How much slower, if at all, would this
decryption circuit be than the encryption circuit from Part B? [2 pt]
_______ ns
(D) Outline (in writing) a possible solution to handling messages of any length (e.g., ones that
are much longer than the key), assuming that we only have one instance of the encryption
circuit (i.e., we can't spawn extra circuitry on the fly). [3 pt]