Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C Programming assignment. Please help create this enigma machine. Our task here is to implement an encryption program similar to the German Enigma machine. Our

C Programming assignment.

Please help create this enigma machine.

Our task here is to implement an encryption program similar to the German Enigma machine. Our Enigma machine will consist of three rotors and one reflector. So every complete rotation of the right rotor moves the middle rotor one position. Every complete rotation of the middle rotor moves the left rotor one position. (A complete rotation of the left rotor doesnt make any difference, for us the reflector never moves.) Requirements: Implement the machine as described for the 26-letter alphabet. The input to the program is as follows: A line of 26 numbers which set the permutation of the right rotor. There are spaces between the numbers. A line of 26 numbers that sets the permutation for the middle rotor. Spaces here too. A line of 26 numbers that sets the permutation for the left rotor. Spaced here as well. A line of 26 numbers that indicate the connections on the reflector. Also spaced apart. An arbitrary amount of text, which you read a character at a time and encrypt using the algorithm described here. Only encrypt characters if they are alphabetic. You should convert everything to UPPER CASE. For other characters like space and punctuation, just pass them through intact, and you would NOT advance the rotors if it is not alphabetic. The letter A would map to the first slot on the right rotor, the letter B would map to the second sloot on the right rotor, and so on for the remaining letters.

Here is an example input file:

14 2 18 19 6 21 3 20 7 8 22 9 23 11 0 17 12 13 4 16 15 5 25 24 1 10 21 11 4 12 0 15 3 18 17 2 16 1 20 19 7 24 23 8 25 9 10 22 14 13 6 5 13 4 16 15 5 25 1 24 14 2 18 19 6 21 3 11 0 12 17 20 7 8 9 22 23 10 12 7 22 11 17 6 5 1 21 13 25 3 0 9 18 16 15 4 14 24 23 8 2 20 19 10 The words are next. Good luck!

Notice that for the first three rows, which are the right rotor, the middle rotor and the left rotor, it is always the case that rotor[i]!=i (no input goes to the same output). For the fourth line it must be the case that reflector[i]==j and i!=j and reflector[j]==i for all values in that line. This is because if for example 16 is wired to 12, then 12 is obviously wired to 16. Also, a permutation should never have the same number in it twice. Print an error message and exit the program if theres problems with the input file. The output of the program should have two parts: A duplicate of the first four lines, as they were originally in the data file. You can have the spacing slightly different if you need to but the values should all be there. The remaining text of the data file, encrypted according to the settings. In other words, it should be possible to give you a file which you use for encryption, then take the output and use it for decryption.

Since the Enigma is symmetric (remember if I encrypt A -> E then also E -> A) and the words in the output should match the original, except that they will be in upper case.

Here are some suggested functions:

int readrotor( int r[ ALPHASIZE ] ); void printrotor( const int r[ ALPHASIZE ] ); int readreflector( int r[ ALPHASIZE ] ); void advance( int r[ ALPHASIZE ] ); void invert ( const int rotor[ ALPHASIZE ], int invertedRotor[ ALPHASIZE ] );

readrotor does just that, reading one rotor worth of data from the input file, while printrotor does the opposite. readrotor and readreflector return true (non-zero) if the data was OK. The function advance will rotate a rotor one position, in place. The function invert has to make the opposite array from the rotor. The rotors and reflector can be implemented as a single dimension array of integers. When going from left to right, inverted copies of the rotor arrays can be useful for the conversion.

For example to convert a rotor array to an inverted one, simply do:

for( i = 0; i < ALPHASIZE; i++ ) invertedRotor[ rotor[ i ] ] = i;

You will get output similar to this:

The right rotor has gone around, so we are advancing the middle one.

Now encrypting 'A', rotor positions are L=0, M=3, R=0

Current rotor settings:

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25

| | | | | | | | | | | | | | | | | | | | | | | | | |

R: 14 2 18 19 6 21 3 20 7 8 22 9 23 11 0 17 12 13 4 16 15 5 25 24 1 10

M: 13 6 5 21 11 4 12 0 15 3 18 17 2 16 1 20 19 7 24 23 8 25 9 10 22 14

L: 13 4 16 15 5 25 1 24 14 2 18 19 6 21 3 11 0 12 17 20 7 8 9 22 23 10

L M R

4 <-- 1 <-- 14 <-- 0/'A'

|

17 --> 18 --> 10 --> 25/'Z'

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David Kroenke, David Auer, Scott Vandenberg, Robert Yoder

8th Edition

013460153X, 978-0134601533

More Books

Students also viewed these Databases questions

Question

39 Job evaluation methods.

Answered: 1 week ago

Question

What is the basis for Security Concerns in Cloud Computing?

Answered: 1 week ago

Question

Describe the three main Cloud Computing Environments.

Answered: 1 week ago