Reputation: 51
I have this bit of code:
[deleted due to unwanted plagiarism]
This is a simplified version of the Enigma machine used during World War II. The decrypting part of this code does not work well and returns HFFDGRHC instead of HELLOBOY. Would anyone know how to fix this problem?
Assignment: Imitate a Enigma cipher: The twist of the ENIGMA machine was that there were actually 26 different rotating cyphers, and a new cypher was chosen for each letter based on the output of the previous letter. Hint: Add a sum of the previous letter and previous cipher key for encryption. Using this information, figure how to decrypt rather than encrypt.
Upvotes: 2
Views: 97
Reputation: 425073
The clue is here:
Add a sum of the previous letter and previous cipher key for encryption.
You were not adding the previous key to the new key.
Change the key rolling line to:
key = (key + newLetter) % 26;
Output is now "HELLOBOY"
Upvotes: 1