A company has asked you to write a programthat encrypts the data so that it can
ID: 3620856 • Letter: A
Question
A company has asked you to write a programthat encrypts the data so that it can be transmitted more securely.Your program should read a four-digit integer and encrypt it asfollows: Replace each digit by (the sum of that digit plus 7)modulus 10. Then, swap the first digit with the third, swap thesecond digit with the fourth and print the encryptedinteger. Create an Encryptclass to do the encrypting, and write a main function to ask for input.Example input is 1234 and the encrypted number is 124.
Can somebody help with the pseudocode?
Explanation / Answer
I'm not quite sure I understand the whole encryption algorithm. If you take 1234. (8)(9)(10)(11) // Add 7 to each digit 8901 // mod 10 each digit 0981 // swap first and third 0189 // swap second and fourth Shouldn't the encrypted number be 189? But anyway, here's some pseudocode for the above algorithm. 1. Extract digits from the integer you want to encrypt There's lots of way to do it depending on language, but here's one way. Let given_int be the integer you want to encrypt. I numbered the digits 1-4 from left to right. digit 4 = given_int % 10 digit 3 = ((given_int - digit 4) / 10) % 10 digit 2 = ((( (given_int - digit 4) / 10) - digit 3) / 10) % 10 digit 1 = (((( (given_int - digit 4) / 10) - digit 3) / 10) - digit 2) / 10 2. for(each of the 4 digits) digit = (digit + 7) % 10 3. swap digit 1 and digit 3 swap digit 2 and digit 4 4. reassemble the digits back into a single integer encrypted number = digit 1 * 1000 + digit 2 * 100 + digit 3 * 10 + digit 4 Hope this helps.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.