The Enigma Machine The encryption algorithm is: For each character in a String: 1. Extract each character from a String as a char. 2. Convert the character to its Unicode value. 3. Unicode divided by 10 to get the first encoded character as an int. 4. Unicode modulus 10 to get the second encoded character as an int. 5. Convert each of the two integers to its Unicode character code. 6. Concatenate both of the characters to the end of a String. The final String (after concatenation) contains the encrypted message. Working through an example: char letter = 'A' from the input String 'A' -> 65 65 / 10 -> 6 65 % 10 -> 5 6 + 48 -> 54 -> '6' 5 + 48 -> 53 -> '5' encryptionString = encryptionString + uniDigit1 + uniDigit2 To Decrypt our Secret Coded Message, We Need to Reverse the Above Steps! (Why?) The decryption algorithm is: For each pair of encrypted characters: 1. Convert the first and second characters of the pair to its Unicode value. 2. Convert the first and second characters to an integer value. 2. Decrypted Unicode code = firstCharacter * 10 + secondCharacter. 3. Convert the Unicode to a character. 4. Append the character to a String. The final String (after concatenation) contains the decrypted message. Working through an example: char1 = '6' from the input string char2 = '5' from the input string '6' - 48 -> 6 '5' - 48 -> 5 letter = 6 * 10 + 5; OutputString = OutputString + letter Notice that with our two-digit conversion technique, Unicode characters with codes higher than 99 ('c') will no longer appear as numbers. For example: H e l l o W o r l d ! 72 :1 :8 :8 ;1 32 87 ;1 ;4 :8 :0 33 Write a program that encrypts and decrypts text into its Unicode equivalent. For example, the letter "A" would encrypt into "65" and "123" encrypts into "495051". All encrypted letters and digits become two character values that are stored as Strings. Decryption returns the Unicode encoded String to its original letters and digits. When letters go beyond lowercase 'c', the ciphertext is no longer purely numbers but includes leading characters such as ':'. Open up Eclipse and create a new Java file called Enigma.java. Within your program, define the two methods, one for encryption and one for decryption as follows: method name: encrypt: Converts a String of uppercase letters and digits into their Unicode equivalent. Lowercase letters may have non-digit characters. Parameter(s): One String parameter for the plaintext to encrypt Prints a ciphertext String of Unicode encoded letters and digits with two characters of output for each character of input. Returns nothing method name: decrypt: Converts a Unicode encrypted String back into letters and digits Parameter(s): One String parameter for the ciphertext to decrypt. Prints a plaintext String of letters and digits equivalent to the original un-encrypted String. Returns nothing Both methods should have a full Javadoc comment (-2 for missing or incorrect Javadoc comments) Your program must work identically to the sample output below: *** Unicode Encryption *** Enter "e" to encrypt, "d" to decrypt or "x" to exit (e/d/x): z Unrecognized command: z Enter "e" to encrypt, "d" to decrypt or "x" to exit (e/d/x): e Enter the String to encrypt: abcABC123 ciphertext: 979899656667495051 Enter "e" to encrypt, "d" to decrypt or "x" to exit (e/d/x): d Enter the String to decrypt: 979899656667495051 plaintext: abcABC123 Enter "e" to encrypt, "d" to decrypt or "x" to exit (e/d/x): e Enter the String to encrypt: Hello World! ciphertext: 72:1:8:8;13287;1;4:8:033 Enter "e" to encrypt, "d" to decrypt or "x" to exit (e/d/x): d Enter the String to decrypt: 72:1:8:8;13287;1;4:8:033 plaintext: Hello World! Enter "e" to encrypt, "d" to decrypt or "x" to exit (e/d/x): x Goodbye.
(Intro to Java)
Avoid using breaks
The Enigma Machine
The encryption
Working through an example:
char letter = 'A' from the input String 'A' -> 65To Decrypt our Secret Coded Message, We Need to Reverse the Above Steps! (Why?)
The decryption algorithm is:
For each pair of encrypted characters:Working through an example:
char1 = '6' from the input stringNotice that with our two-digit conversion technique, Unicode characters with codes higher than 99 ('c') will no longer appear as numbers. For example:
H e l l o W o r l d !- Write a program that encrypts and decrypts text into its Unicode equivalent.
For example, the letter "A" would encrypt into "65" and "123" encrypts into "495051". All encrypted letters and digits become two character values that are stored as Strings. Decryption returns the Unicode encoded String to its original letters and digits. When letters go beyond lowercase 'c', the ciphertext is no longer purely numbers but includes leading characters such as ':'.
- Open up Eclipse and create a new Java file called Enigma.java.
- Within your program, define the two methods, one for encryption and one for decryption as follows:
- Converts a String of uppercase letters and digits into their Unicode equivalent. Lowercase letters may have non-digit characters.
- Parameter(s): One String parameter for the plaintext to encrypt
- Prints a ciphertext String of Unicode encoded letters and digits with two characters of output for each character of input.
- Returns nothing
- Converts a Unicode encrypted String back into letters and digits
- Parameter(s): One String parameter for the ciphertext to decrypt.
- Prints a plaintext String of letters and digits equivalent to the original un-encrypted String.
- Returns nothing
- Both methods should have a full Javadoc comment (-2 for missing or incorrect Javadoc comments)
- Your program must work identically to the sample output below:
Trending now
This is a popular solution!
Step by step
Solved in 2 steps