Question: whats wrong with my code its printing CMAPAHNNEYGSMQU when its supposed to print BRIMRTQMCKUTVF U Task 3 - Enigma For this task, you need to

whats wrong with my code its printing CMAPAHNNEYGSMQU when its supposed to print BRIMRTQMCKUTVF U
Task 3- Enigma
For this task, you need to implement a simplified version of the famous Enigma cipher that was used by the axis powers in WWII. The cracking of the Enigma cipher was also a seminal moment in the history of computer science. You can learn a bit more about this in the History section on Enigma.
For a detailed explanation of the workings of this cipher, first read our write-up in the Enigma Operation for this PA section. This will provide you with all the details you need. Make sure you thoroughly understand the Enigma operation before you go on to the coding part. Note that the Enigma treats spaces just like other characters (so we are again working with a set of 27 symbols, as with the substitution cipher). Again, index_of_char() and char_at_index() will be extremely helpful in implementing your code.
The function you need to implement has the following functionality:
cipher_enigma(arg1, arg2, arg3, arg4)
The first argument, arg1, is a string containing the data that needs to be encrypted or decrypted. It is not modified by this function.
The second argument, arg2, is a string that will contain the result of the encryption or decryption.
The third argument, arg3, is a non-negative integer number (of at most 4 digits), specifying the key of the Enigma cipher. The two rightmost decimal digits (what are called the least significant digits) of this number represent the initial shift (to right!) of the inner rotor (what we called key_part_1 in Enigma Operation for this PA). The next two digits give the initial shift (to the right) of the middle rotor (what we called key_part_2). For example, the number 1329 means that the initial shift of the inner rotor is 29 positions (which is the same as 2 positions, as it wraps around after 27 turns) and that of the middle rotor is 13 positions. So the following keys all result in the same starting positions of the rotors: 1302,1329,9483, etc.
For the fourth argument, arg4, which is an integer, we either pass ENCRYPT or DECRYPT, which are the two constants that we defined.
The function returns nothing.
The default positions for all the rotors (i.e., without any initial shift) and the organization of the symbols on each of the rotors is as shown in Enigma Operation for this PA. This information is also already included in the ciphers.c starter code, so you dont have to copy it from this document. When testing your Enigma, make sure it also works for messages longer than 27 symbols (to capture the effects of the rotors moving after encrypting each symbol).
For this task, you only need to implement the encryption functionality of the Enigma cipher. This means that you only need to implement what happens when arg4 is ENCRYPT. Again, you can implement decrypt for extra credit (see Task 4- Decryption of the Substitution and Enigma Ciphers).```
void cipher_enigma(char input[], char output[], int key, int arg4){
char outer_rotor[]= "BDFHJLNPRTVXZACEGIKMOQSUWY ";
char middle__rotor[]= "EJOTYCHMRWAFKPUZDINSXBGLQV ";
char inner_rotor[]= "GNUAHOVBIPWCJQXDKRYELSZFMT ";
int middle_shift =(key %100)%27;
int inner_shift =(key /100)%27;
printf("%-\overline{d}
%d
", inner_shift, middle_shift);
int outer_shift =0;
int size = string_length(input);
for (int i =0; i size; i++){
char character = input[i];
int index_inside = index_of_char(inner_rotor, inner_shift, character);
//char index_inside = chr_at_index(inner_rotor, inner_shift, input[i]);
char mapping == outer_rotor[index_inside];
int index_middle = index_of_char(middle_rotor, middle_shift, mapping);
char mapping2= outer_rotor[index_middle];
output[i]= outer_rotor[index_middle];
//output[i]= mapping2;
//inner_shift =(inner_shift +1)%27;
//if (iner_shift ==0){
// middle_shift =(middle_shift +1)%27;
//}
inner_shift = increment(inner_shift, 1,26);
if (inner_shift ==0){
miiddle_shift = increment(middle_shift, 1,26);
}
}
output[size]='\0';
}|
```
whats wrong with my code its printing

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 Programming Questions!