You are serious about security, so encryption is a must. Here is one encryption algorithm that crosses your
mind for encrypting four-digit integers (i.e., integer numbers between 1, 000 and 9, 999):
- Ask the user to provide an integer to encrypt and a secret key. The secret key is an integer between
0 and 9.
- Consider each digit as an ASCII character. Modulo the ASCII value of each digit (in decimal) by 48.
- For each digit, add key to the result of the previous step and divide it by 10.
- Use the remainder from the division of the previous step to represent each digit. Then, swap the first
digit with the fourth, and the second with the third.
- Print the encrypted integer to the console.
Write a Java program called EncryptionMachine to implement the algorithm. Please comment your code to indicate each step in the algorithm that your code reflects.
Additionally, answer the following question:
What step in the algorithm, if any, might be redundant in the encryption process? You should include your answer in the header comment.
Here is what the output should look like on your console (please make sure you use the exact wording):
Enter an integer to encrypt (between 1000 and 9999): 6835
Enter the secret key (between 0 and 9): 2
The encrypted integer is: 7508