Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please help how do I write this code: (Enforcing Privacy with Cryptography) The

ID: 3629275 • Letter: P

Question

Please help how do I write this code: (Enforcing Privacy with Cryptography)

The explosive growth of Internet communications and data storage on Internet-connected computers has greatly increased privacy concerns. The field of cryptography is concerned with coding data to make it difficult (and hopefully--with the most advanced schemes--impossible) for encrypting and decrypting data. A company that wants to send data over the Internet has asked you to write a program that will encrypt it so that it may be transmitted more securely. All the data is transmitted as four-digit integers. Your application should read a four-digit integer entered by the user and encrypt it as follows: Replace each digit with the result of adding 7 to the digit and getting the remainder after dividing the new value by 10. Then swap the first digit with the third, and swap the second digit with the fourth. Then print the encrypted integer. Write a separate application that inputs an encrypted four-digit integer and decrypts it (by reversing the encryption scheme) to form the original number.

Explanation / Answer

Depending if the input is an actual integer, 1234, or a string representing an integer, "1234", you may have to parse it first before you do anything (Integer.parseInt(string), will have to use try/catch) Say the integer is k: - first digit = k/1000 (will truncate the decimal since it is an integer) - second digit = (k/100) % 10 (will get the first two digits, then take the remainder divided by 10, leaving the second digit) - etc... From there it should be straight forward, % is the mod operator (remainder after dividing by a number), once you have the digits correct, you can piece them back together by multiplying by the right digit place (1000, 100, 10, 1) and adding them. Follow same steps more or less for decryption (add 10 and subtract 7 to reverse the mod-ing part) Good luck!

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote