Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Here is C++ code for a decryption scheme for the Feistel cipher1 with linear con

ID: 3760717 • Letter: H

Question

Here is C++ code for a decryption scheme for the Feistel cipher1 with linear congruential generator (LCG)2

I NEED HELP CONVERTING THIS CODE TO MATLAB FORMAT!!
Program must have the following!!:

• Use a for loop

• Use the bitxor function

• Query user for ciphertext and original key values

Sample Output (Two possibilities shown)

Enter ciphertext to decrypt: 3e63

Enter original key value: 13

He

Enter string to encrypt: 340a66537a574225622d660e760e276e496f416951796333252c7063

Enter original key value: 101

This is an encrypted string Note there is one hexadecimal value (2 characters 0-f) for each plain text character entered. The 0x prefix is not added here since we know it is hexadecimal.

#include <cstdlib>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <ctime>

using namespace std;

int main() {


// initialize variables
string phrase = "a";
int key = 0;
const int A = 101;
const int C = 12;
const int M = 121;
int left = 0;
int right = 0;
int temp = 0;


// prompting user to input string
cout << "Enter string to encrypt: ";
getline(cin, phrase);
cout << phrase << endl;
  
// key
cout << "Enter a key value: ";
cin >> key;
cout << key << endl << endl;

// pad to even length
if((phrase.size() % 2) != 0){
phrase.append(" ");
}
// first loop cycles through string
for(int i = 0; i <= phrase.size() - 1; i += 2)
{
left = phrase.at(i);
right = phrase.at(i + 1);
  
// Feistal cipher second loop
for(int j = 0; j < 3; j++)
   {
   temp = right;
     
// Third loop is to find LCG
for(int k = 0; k < key + j; k++)
   {
     
   right = ((A * right + C) % M);
     
}
right = left ^ right; // compares left and right character
left = temp;
  
  
}
if (right < 16) {
    cout << "0";
   }
   cout << hex << right; // prints left character
   if (left < 16) {
      cout << "0";
   }
   cout << hex << left; // prints right character

}
return 0;   
}

Explanation / Answer

A = 101;
C = 12;
M = 121;
left = 0;
right = 0;
temp = 0;
phrase = input('Enter string to encrypt: ', 's');
key = input('Enter a key value: ');
if mod(length(phrase), 2) == 1
phrase = horzcat(phrase, ' ');
end

for i = 1:length(phrase)
left = phrase(i);
right = phrase(i + 1);
for j = 1:3
temp = right;
for k = 1:key + j
right = mod((A * right + C), M);
end
right = bitxor(left, right);
left = temp;
end
if right < 16
disp(0);
end
disp(hex);
if right < 16
disp(0);
end
disp(hex);
disp(left);
i = i + 1;
end

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote