Can someone help me with this issue. How can I decrypt the message, seems to me it's impossible to return the original message.
Code:
#include<stdio.h>
#include<ctype.h>
#include <stdio.h>
#include <string.h>
#define max_alfabeet 26
const char * alfa = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const char * rotor_sifrid [] = {
"AJDKSIRUXBLHWTMCQGZNPYFVOE",
"BDFHJLCPRTXVZNYEIWGAKMUSQO",
"ESOVPZJAYQUIRHXLNFTGKDCMWB",
"AKMFLGDQVZNTOWYHXUSPAIBRCJ",
"FVPJIAOYEDRZXWGCTKUQSBNMHL"
};
const char * rotor_tyhim [] = {"S", "U", "W", "M", "T"};
const char * reflector [] = {"VZBRGITYUPSDNHLXAWMJQOFECK",
"YRUHQSLDPXNGOKMIEBFZCWVJAT"
};
struct rotor {
int shift;
int jan;
const char * siffer;
const char * void;
};
struct Enigma {
int rotor_collection;
const char * reflector;
struct Rotor rotors [5];
};
// Initial setup
struct Rotor New_Rotor (struct Enigma * machine, int rotor_number, int shift) {
struct Rotor r;
r.high = shift;
r.and n = 0;
r.siffer = rotor_products [rotor_number];
r.tyhimik = rotor_tyhim [rotor_number];
machine> rotor_count ++;
return r;
}
// The function will show if and how many letters can be found in the list
int str_ index (const char * str, int taht) {
char * pos;
int index;
pos = strchr (str, taht);
if (pos) index = (int) (pos - str);
else index = -1;
return index;
}
// Observes that the rotor is in a cavity and changes its location a moment later
void rotor_ movement (struct rotor * rotor) {
if (str_ index (rotor-> blank, (int) alpha [rotor-> shift])> = 0) {
rotor-> = = 1;
}
rotor-> shift ++;
rotor-> displacement = rotor-> displacement% max_alfabeet;
}
// Returns the location of the exit index.
int rootor_tagasi (struct rotor * rotor, int index) {
index = (index + rotor-> shift)% max_alfabeet;
index = str_ index (rotor-> siffer, alpha [index]);
index = (max_alfabeet + index - rotor-> shift)% max_alfabeet;
return index;
}
// Generating machine + 5. Setting the rotor on the machine
int main () {
struct Enigma machine = {};
int i, j, index, lim = 500;
char box [lim];
char alg [5];
printf ("enter 5 digit sequence (bcdpl) n");
gets (alg);
for (i = 0; i <5; i ++) {
machine.rootors [i] = new_rootor (& machine, i, str_ index (rotor_friders [i], (int) alg [i]));
}
FILE * f = fopen ("tere.txt", "r");
if (f)
{
fgets (box, lim, f);
}
fclose (f);
printf ("Original text from file:% s", box);
printf ("Output Text:");
for (j = 0; j <lim; j ++) {
if (box [j] == '0') {
break;
}
// Missing symbols that do not belong to the alphabet used
if (! isalpha (box [j]) {
memmove (& box [j], & box [j + 1], strlen (box) - j);
j--;
continue;
}
box [j] = toupper (box [j]);
index = str_ index (alpha, box [j]);
rotor motion (& machine rotors [0]);
if (str_ index (machine rotors [1] .tyhimik, alpha [machine rotors [1] .direction)> = 0) {
rotor movement (& machine rotors [1]);
}
// when the rotor has passed through the gap and noted the following, the next rotor will move forward
for (i = 0; i <machine rotor_count - 1; i ++) {
if (machine rotors [i] .jarg) {
machine rotors [i] .and n = 0;
rotor motion (& machine rotors [(i + 1)% 5]);
}
}
// Moves to a keystroke
for (i = 0; i <machine rotor_count; i ++) {
index = rootor_tagasi (& machine.rootors [i], index);
}
box [j] = reflector [index];
index = str_ index (alpha, box [j]);
// similar to the above
for (i = machine.rotor_country - 1; i> = 0; i--) {
index = rootor_tagasi (& machine.rootors [i], index);
}
box [j] = alpha [index];
printf ("% c", box [j]); // typing the answer alphabetically
}
f = fopen ("tere.txt", "w");
if (f)
{
fputs (box, f);
}
fclose (f); // close the file
printf ("n");
system ("pause");
}