fix program2
This commit is contained in:
parent
9a8c9a3771
commit
570bd3698a
@ -44,7 +44,7 @@ module program1_tb ();
|
||||
assign LFSR_ptrn[8] = 8'h7B;
|
||||
|
||||
always_comb begin
|
||||
pt_no = $random;
|
||||
pt_no = $urandom_range(0, 8);
|
||||
if(pt_no>8) pt_no[3] = 0; // restrict pt_no to 0 through 8
|
||||
lfsr_ptrn = LFSR_ptrn[pt_no]; // look up and engage the selected pattern; to data_mem[62]
|
||||
end
|
||||
|
@ -22,8 +22,8 @@ module program2_tb () ;
|
||||
// note in practice your design should be able to handle ANY ASCII string that is
|
||||
// restricted to characters between space (0x20) and script f (0x9f) and shorter than
|
||||
// 55 characters in length
|
||||
string str1 = "Mr. Watson, come here. I want to see you."; // sample program 1 input
|
||||
// string str1 = " Knowledge comes, but wisdom lingers. "; // alternative inputs
|
||||
string str1 = "Knowledge comes, but wisdom lingers"; // sample program 1 input
|
||||
// string str1 = " . "; // alternative inputs
|
||||
// string str1 = " 01234546789abcdefghijklmnopqrstuvwxyz. "; // (make up your own,
|
||||
// string str1 = " f A joke is a very serious thing."; // as well)
|
||||
// string str1 = " Ajok "; //
|
||||
@ -46,13 +46,14 @@ module program2_tb () ;
|
||||
assign LFSR_ptrn[7] = 7'h7E;
|
||||
assign LFSR_ptrn[8] = 7'h7B;
|
||||
always_comb begin
|
||||
pt_no = 0; //$random>>22; // or pick a specific one
|
||||
if(pt_no>8) pt_no[3] = 0; // restrict to 0 through 8 (our legal patterns)
|
||||
lfsr_ptrn = LFSR_ptrn[pt_no]; // engage the selected pattern
|
||||
end
|
||||
pt_no = 4;
|
||||
//pt_no = $urandom_range(0, 8);
|
||||
if(pt_no>8) pt_no[3] = 0; // restrict pt_no to 0 through 8
|
||||
lfsr_ptrn = LFSR_ptrn[pt_no]; // look up and engage the selected pattern; to data_mem[62]
|
||||
end
|
||||
// now select a starting LFSR state -- any nonzero value will do
|
||||
always_comb begin
|
||||
LFSR_init = 'b1;//$random>>2; // or set a value, such as 7'b1, for debug
|
||||
LFSR_init = $urandom;//$random>>2; // or set a value, such as 7'b1, for debug
|
||||
if(!LFSR_init) LFSR_init = 7'b1; // prevents illegal starting state = 7'b0;
|
||||
end
|
||||
|
||||
|
@ -34,20 +34,20 @@ tap_init: LDI #d64
|
||||
PUT r11 // set read pointer to 64
|
||||
LDI #d0
|
||||
PUT r12 // set write pointer to 0
|
||||
LDI #d10
|
||||
PUT r8 // load 10 into preamble counter
|
||||
LDI #d9
|
||||
PUT r8 // load 9 into preamble counter
|
||||
LDI #d64
|
||||
PUT r9 // load 64 (total encryption length) to r9
|
||||
LDI done
|
||||
NXT r10 // decrement tap selection by 1, starts at 9 for the first iteration
|
||||
JEZ r0 // if no more taps left that didn't work, raise the done flag
|
||||
LDI tap_init
|
||||
LDI lut_return
|
||||
PUT r5 // put the tap_loop address in r5
|
||||
LDI tap_lut
|
||||
ADD r10
|
||||
ADD r10 // add 2*tap select to tap_lut location, results in location of selected tap pattern
|
||||
JMP r0 // jump to LUT, which loads the tap pattern into r0
|
||||
PUT r6 // tap pattern now in r6
|
||||
lut_return: PUT r6 // tap pattern now in r6
|
||||
LDW r11 // get the first preamble character
|
||||
PUT r1 // put cipher text into r1
|
||||
LDI #d32 // load expected space character
|
||||
@ -59,13 +59,14 @@ tap_init: LDI #d64
|
||||
NXT r9 // decrement total encryption chars remaining
|
||||
tap_loop: LDI lfsr_routine
|
||||
JAL r0 // jump to lfsr routine which calculates next state in r7
|
||||
LDI #d0 // load space char expected plaintext
|
||||
LDI #d32 // load space char expected plaintext
|
||||
XOR r7
|
||||
CLB r0 // clear leading bit in the expected ciphertext
|
||||
PUT r1 // store expected cipher text in r1
|
||||
LDI tap_init
|
||||
PUT r2 // load the outer loop top into r2
|
||||
LDW r11 // load actual ciphertext
|
||||
CLB r0 // clear leading bit for r0 since we do not expect any errors for this program
|
||||
SUB r1 // subtract actual from expected, result of 0 means matching
|
||||
JNZ r2 // jump to outer loop (picks new tap pattern) if the actual cipher was not equal to the expected
|
||||
LDI #d32 // load preamble char
|
||||
@ -78,12 +79,13 @@ tap_init: LDI #d64
|
||||
JEZ r0 // if r8 (preamble counter) is zero, then all preamble have matched and current tap pattern is correct, jump to main loop
|
||||
LDI tap_loop
|
||||
JMP r0 // jump to tap_loop if characters matched but preamble is not over
|
||||
main_loop: LDW r11 // load the next ciphertext byte
|
||||
main_loop: LDI lfsr_routine // load address for the lfsr_routine label
|
||||
JAL r0 // jump to the lfsr_routine label
|
||||
LDW r11 // load the next ciphertext byte
|
||||
CLB r0 // clear leading bit because we do not expect errors
|
||||
XOR r7 // bitwise XOR the current state with ciphertext space to generate plaintext
|
||||
CLB r0 // clear the leading bit of the plaintext as in requirements
|
||||
STW r12 // store plaintext to write pointer
|
||||
LDI lfsr_routine // load address for the lfsr_routine label
|
||||
JAL r0 // jump to the lfsr_routine label
|
||||
NXT r11 // increment read pointer
|
||||
NXT r12 // increment write pointer
|
||||
LDI done // load address of label done
|
||||
|
Reference in New Issue
Block a user