JAVA Encryption Algorithm: Mapping and Encoding in Java

Verified

Added on  2020/05/28

|6
|671
|69
Practical Assignment
AI Summary
The JAVA Encryption Assignment involves developing a program to map characters from the system's alphabet {a-z, 0-9, . , , !, } in a new order provided by the user. The program checks for correctness, ensuring each character maps uniquely and verifies no duplicates exist. It then prompts the user to enter a sentence that gets encrypted using these mappings; any character not within the given set results in an error. An encrypted output is displayed, with options to decrypt or exit. Users can either encrypt new sentences or decrypt previous ones, providing comprehensive functionality for encoding and decoding messages. The assignment includes creating a UML class diagram to visualize program components and methods such as encryption and decryption.
Document Page
Running head: JAVA ENCRYPTION ASSIGNMENT
Encryption Assignment
Name of the student:
Name of the University:
Author note:
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
1
JAVA ENCRYPTION ASSIGNMENT
Table of Contents
Program Description..................................................................................................................2
UML Class Diagram..................................................................................................................3
Algorithm...................................................................................................................................3
Output.........................................................................................................................................5
Document Page
2
JAVA ENCRYPTION ASSIGNMENT
Program Description
The program is designed to display the set of characters that are present in the
system’s alphabet {a-z, 0-9 and the symbols namely full stop (.), comma (,), exclamation
mark (!) and space ( )}. The user is then asked to re-enter the values of the alphabet but in a
different order. The program then checks if the user correctly enters all 40 characters into the
new alphabet. Then it ensures that a proper one-to-one mapping has taken place. This check
confirms that each character maps back to only one character from the original alphabet set.
Also does the program checks for duplicate entries. In case any of the above cases are
violated, the user is asked to enter the mapping set again.
Once the user has successfully mapped the set of alphabet, the program asks the user
to enter a sentence. First, the program checks if the sentence contains any character that is out
of context from the given alphabet set. Then, it then encrypts the sentence using the mapping
values. The program picks each character from the sentence, searches for it in the main
alphabet and then tracks back the corresponding mapped character. Likewise, the whole
sentence is traversed and the encrypted sentence is displayed.
The user is then given the choice to continue with another sentence, decrypt back the
encrypted message or to exit. If the user choses to decrypt, the reverse process is carried on to
search out the actual character that was mapped to the encrypted characters in the encrypted
sentence.
Document Page
3
JAVA ENCRYPTION ASSIGNMENT
UML Class Diagram
Algorithm
START
Step 1. Initialize static variable ‘alpha’ inside class ‘encryption’ to null
Step 2. Display student information
Step 3. Update the alphabet string with the English alphabet, numbers, symbols and
space.
Step 4. User input mapped alphabet set.
Step 5. Check if user’s alphabet set has 40 characters
Step 6. If yes, go to next step else step 4.
Step 7. For there is character in the alphabet go to step 8, then go to step 12
Step 8. Check if each of user’s character is from the original alphabet.
Step 9. If yes, continue else go to step 4
Step 10. Check if each character occurs only once.
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
4
JAVA ENCRYPTION ASSIGNMENT
Step 11. If yes, continue else go to step 4
Step 12. User input sentence
Step 13. For there is character in the sentence go to step 14, then go to step 12
Step 14. Check if each character of user’s sentence is from the original alphabet.
Step 15. If yes, continue else go to step 12
Step 16. Call encryption ( ) method.
Step 17. Print encrypted string.
Step 18. Print menu
Step 19. If user enters 1, go to step 12
Step 20. If user enters 2, call decrypt ( ) method and display decrypted message and go
to step 18.
Step 21. If user enter 3, print THANK YOU message and go to step 23
Step 22. If no choice matches then print error message and go to step 18
Step 23. End
Encrypt ( ) method
Step 1. For every character in input sentence, go to step 2
Step 2. Add to ‘encrypted’ string, the character that is present in the user’s alphabet at
the index of where that character is found in the main alphabet.
Step 3. Return encrypted string.
Step 4. End
Decrypt ( ) method
Step 1. For every character in input sentence, go to step 2
Step 2. Add to ‘decrypted’ string, the character that is present in the main alphabet at
the index of where that character is found in the user’s alphabet.
Document Page
5
JAVA ENCRYPTION ASSIGNMENT
Step 3. Return decrypted string.
Step 4. End
STOP
Output
chevron_up_icon
1 out of 6
circle_padding
hide_on_mobile
zoom_out_icon
[object Object]