Question: build the decryption scheme for the Feistel cipher with linear congruential generator (LCG) you wrote earlier in C++. The encryption and decryption schemes are shown

build the decryption scheme for the Feistel cipher with linear congruential generator (LCG) you wrote earlier in C++. The encryption and decryption schemes are shown in the diagram (you only need to decrypt in this assignment). The F represents a type of trapdoor function (a one-way pseudorandom function, meaning easy to go one way, difficult to go backwards). Use a LCG for this function. K0, K1, etc. are key values used in the function. Here, we will set K0 to the number of iterations of the LCG. The user will enter K0, and after that set Kn+1 = Kn + 1 (if K0 = 12, K1 = 13, etc.) The circle-with-cross symbol is a bit-wise exclusive or function, which in Matlab is bitxor. Use the same number of Feistel rounds (3) as encryption. Your program will ask the user for a text string to decrypt and a key (K0) that was used to encrypt the original message. You will loop through the ciphertext string setting Rn+1 to the first 2 hexadecimal values (corresponding to a single character) and Ln+1 to the third and fourth, and decrypt this with 3 Feistel rounds. Continue to loop through the string of hexadecimal characters. Since the encryption scheme you wrote previously padded odd-numbered strings with a white space, you can assume all hexadecimal strings to decrypt are multiples of 4 (2 hexadecimal values per character, and even number of characters).

After decrypting each 2 characters, append them to a string using the sprintf function that will convert numeric values into the corresponding ASCII characters. Specifically, the decrypted text can be built with the statement below, which forms an array of characters (to be discussed in later weeks):

outputString = [outputString, sprintf('%c%c',left,right)];

NOTE that decryption is the reverse of encryption. You use Kn first, then Kn-1, etc. ending with K0 (which is the initial key value used to encrypt the original text.)

Your program must have the following:

Use a for loop

Use the bitxor function

Use the hex2dec function

Use sprintf function to output decrypted message as characters.

Sample Output (Two possibilities shown)

Input ciphertext: 3e63

Key: 13

Decrypted text: He

--------------------------------------------------------------------------

Input ciphertext: 340a66537a574225622d660e760e276e496f416951796333252c7063

Key: 101

Decrypted text: This is an encrypted string

given code follows

%LCG Constants a=101;c=12;m=121

inputString = '340a66537a574225622d660e760e276e496f416951796333252c7063'; key = 101;

disp(sprintf('Input ciphertext: %s' , inputString)); disp(sprintf('Key: %d' , key)); %start with a empty output string outputString = ''; %your code goes here

disp(sprintf('Decrypted text: %s', outputString));

code solution follows

% LCG constants a=101;c=12;m=121; % Default ciphertext and key. The test will use these values % If you want to test different values, re-define these beginning % on line 8 below inputString = '340a66537a574225622d660e760e276e496f416951796333252c7063'; key = 101; % display to screen disp(sprintf('Input ciphertext: %s',inputString)); disp(sprintf('Key: %d',key)); % start with an empty output string outputString=''; disp(sprintf('Input ciphertext: %s',inputString)); disp(sprintf('Key: %d',key)); % start with an empty output string outputString=''; key = key + 2; for i=1:4:length(inputString) left = hex2dec(inputString(i:i+1)); right = hex2dec(inputString(i+2:i+3)); for fround = 0:1:2 %Feistel Round 3x temp = right; for j=0:1:(key-fround-1) % Loop through key times right = mod((a * right + c), m); end right=bitxor(left, right); left = temp; end outputString = [outputString, sprintf('%c%c',right,left)]; end% your code goes here % your code goes here

disp(sprintf('Decrypted text: %s',outputString));

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!