Question
Programming in C. During World War II, the Germans were using an encryption code called Enigma which was basically an encryption machine that encrypted messages
Programming in C.
During World War II, the Germans were using an encryption code called Enigma which was basically an encryption machine that encrypted messages for transmission. The Enigma code went many years unbroken. Here's How the basic machine works: First Caesar shift is applied using an incrementing number: If String is AAA and starting number is 4 then output will be EFG.
A + 4 = E A + 4 + 1 = F A + 4 + 1 + 1 = G
Now map EFG to first ROTOR such as:
ABCDEFGHIJKLMNOPQRSTUVWXYZ BDFHJLCPRTXVZNYEIWGAKMUSQO
So EFG becomes JLC. Then it is passed through 2 more rotors to get the final value. If the second ROTOR is AJDKSIRUXBLHWTMCQGZNPYFVOE, we apply the substitution step again thus:
ABCDEFGHIJKLMNOPQRSTUVWXYZ AJDKSIRUXBLHWTMCQGZNPYFVOE
So JLC becomes BHD. If the third ROTOR is EKMFLGDQVZNTOWYHXUSPAIBRCJ, then the final substitution is:
ABCDEFGHIJKLMNOPQRSTUVWXYZ EKMFLGDQVZNTOWYHXUSPAIBRCJ
So BHD becomes KQF. Final output is sent via Radio Transmitter.
Input
Line 1: ENCODE or DECODE Line 2: Starting shift N Lines 3-5: BDFHJLCPRTXVZNYEIWGAKMUSQO ROTOR I AJDKSIRUXBLHWTMCQGZNPYFVOE ROTOR II EKMFLGDQVZNTOWYHXUSPAIBRCJ ROTOR III Line 6: Message to Encode or Decode
Output
Encoded or Decoded String
Constraints
0 N < 26 Message consists only of uppercase letters (A-Z) 1 Message length < 50
Here is the code provided in C.
#include
/** * Auto-generated code below aims at helping you parse * the standard input according to the problem statement. **/
int main() { char operation[257]; fgets(operation, 257, stdin); int pseudo_random_number; scanf("%d", &pseudo_random_number); fgetc(stdin); for (int i = 0; i < 3; i++) { char rotor[27]; fgets(rotor, 27, stdin); fgetc(stdin); } char message[1025]; fgets(message, 1025, stdin);
// Write an action using printf(). DON'T FORGET THE TRAILING // To debug: fprintf(stderr, "Debug messages... ");
printf("message ");
return 0; }
How do I complete the code so that it works as instructed?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started