Assignment 06

Due: Friday, October 16, 2015 at noon     100 pts

Instructions:  You know how to submit; do it in the usual way. However, this time you will submit multiple files for this programming project.  The cssubmit script will work as usual, picking up all .cpp and .h files in the current directory.  So, make sure you have created a separate directory for your hw 6 program.  Do not create subdirectories in the hw6 directory.

Background: For assignment #4, you wrote a program that would function as a Krusty-nigma de-crypter.  That is, given a string of characters representing a message that had been encrypted using the Krusty-nigma masheen, your program would decrypt the message.  Now, you're going to do it again.  But this time you're going to use functions to accomplish the same task as that in hw 4.  But, there are modifications in this new model of the Krusty-nigma.  The
original was just too simplistic; simplistic to the point that even Barney could figure it out.  So the new model will better approximate the original Enigma machine invented by Frink.

Specifications:  Now, your assignment is to rewrite the code for the Krusty-nigma masheen, except that you are to write your code using functions in a manner that makes the whole project easier to understand and code.  In hw 5, we specified the functions you were to use.  This time, YOU are going to decide what functions to write and use.  Make the decisions wisely. 

Modifications:  First, there are to be 5 (five) disks for the macheen, but still only 3 will be used at any given time.  Thus, the number of possible combinations of translators goes wayyyyy up.  Again, there are still only 3 rotors.  The new disks translate as follows:
  1. disk 4 will replace 'A' with 'B' and 'B' with 'A', replace 'C' with 'D' and 'D' with 'C', replace 'E' with 'F' and 'F' with 'E', etc on down to replacing 'Y' with 'Z' and 'Z' with 'Y'.
  2. disk 5 will
    • replace any letter whose ASCII is a multiple of 3 with the very next letter whose ASCII is a multiple of 3, with the exception of 'Z' which gets replaced with 'B'.  Thus, 'B' -> 'E', 'E' -> 'H', ... , 'Z' -> 'B'.
    • swap the two letters that are between those with ASCII values that are multiples of 3 (as above).  Thus, 'C' -> 'D' and 'D' -> 'C', 'F' -> 'G' and 'G' -> 'F', etc.
    • A remains unchanged.  Thus, well, you know, 'A' -> 'A'.

So you now have 5 disks.  The first three disks are as described in hw 4.

Second, every time a rotor translates a letter, the rotor modifies how the next letter is processed by shifting it in the alphabet.    The amount of shift is dependent on what the last translated letter was; in particular, its ASCII value.   Let's look at an example to make this clear.  Suppose disk #1 is loaded into rotor #1.  Recall that disk 1 translates thusly:  (input + 3)%26 + 65.  Now, if the first letter to be translated is a 'D' (ASCII 68), it translates to (68 + 3)%26 + 65 = 84 = 'T'.  But the masheen uses the ASCII of the last input letter to determine how to shift the next letter to be translated.  The shift is given by (prev_input - 65), and the letter the new input is shifted to is given by ((new_input - 65) + (prev_input - 65))%26 + 65.  So, in our example, suppose the second letter input is a 'M' (ASCII 77).  Since the previous input was 'D',  the 'M' is shifted to ((77 - 65) + (68 - 65))%26 + 65 = 80 = 'P'.  And 'P' is then translated by disk 1 to (80 + 3)%26 + 65 = 70 = 'F'. Looking at the next input to that same rotor, the rotor will first shift the third input letter based on the second input letter.  The shift is (prev_input - 65) again, but now prev_input is 'M' because it was the second letter to be processed.  Thus, supposing the third letter input is a 'V'(ASCII 86), it first gets shifted to ((86 - 65) + (77 - 65))%26 + 65 = 72 = 'H'.  The 'H' is then translated by disk 1 to (72 + 3)%26 + 65 = 'X'.

The net effect of the process described above is that, once a letter is translated by a rotor, the next time that same letter is translated it is translated to a different resulting letter.  Unlike the basic Krusty-nigma, the new improved model will translate any given letter to different letters.  For example, BBB -> UJA using disks 1, 2, and 4 in rotorL, rotorM, rotorR.   This, of course, will just make Barney drink more beer.  And perhaps it will make the other Barney stop that incessant and annoying singing!

Each of the 3 rotors does this shifting in the same manner:  the shift depends on the letter that was previously processed by that rotor.  All letters to be translated by each rotor are going to be shifted before they are translated to a new letter via the disk in that rotor ... except the first letter into each rotor, of course, since they have no previous input.

Think About:  Think about your code.  Think carefully about how to break your code into functions.  Think about how to make it modular, compact, neat, adaptable and modifiable.  Also, think about this:  of the 5 disks described above, only one warrants a switch statement to code.  That one was a product of copious glue consumption by Ralph.

You will be graded on how you manage your functionalization and the efficiency and 'tightness' of your code.

When you submit: 

                    4 3 5 KLJ_I_FPFYGSJHUKEK_SFKIC_JNT_WWO_XZHA.

As always, if you have any questions on the assignment, ask your instructor.  

Here below is a diagrammatic view of how the old masheen worked and how the new and improved masheen works.  It might help you...It might hurt your head.

Displaying Disks


How it looked in Assignment 4


How it will look in Assignment 6