Answered step by step
Verified Expert Solution
Question
1 Approved Answer
A company wants to transmit data through the phone but they fear their lines are monitored. All data is transmitted as four-digit non-negative integers. They
A company wants to transmit data through the phone but they fear their lines are monitored. All data is transmitted as four-digit non-negative integers. They have asked you to write a program in C++ that encrypts their data so that transmission is safer. Note that numbers with fewer than four digits are assumed to have the required zeros on the left in order to be four-digit. For example, the number 52 corresponds to 0052. You won't have to add the zeros to the numbers.
A company wants to transmit data through the phone but they fear their lines are monitored. All data is transmitted as four-digit non-negative integers. They have asked you to write a program in C++ that encrypts their data so that transmission is safer. Note that numbers with fewer than four digits are assumed to have the required zeros on the left in order to be four-digit. For example, the number 52 corresponds to 0052. You won't have to add the zeros to the numbers Your program should have these three functions //function to read a four-digit number int readNumberO;/ int encrypt (int data); //function to encrypt data int decrypt (int data); //function to decrypt data The function int readNumber0 should prompt the user to enter a nonnegative integer. It will then read the number from the input and perform the following correctness checks If the number is negative or has more than four digits, your program should output an appropriate error message and terminate. Ifthe number has fewer than four digits you can assume that the first ones are zeros The function should return the nonnegative four-digit number, if it passes the correctness checks * * o HINT: You can return a negative number for invalid input numbers and use this in your main program to terminate it. The function int encrypt (int data) will encode the four-digit integer given as a parameter in the following way: * Each digit of the number is replaced by (the sum of the digit with the number 7) modulo 10. NOTE: The modulo operator % gives the remainder when the first operand is divided by the second For example, "11 % 4" is equal to 3 (that is, the remainder of 11 divided by 4 is 3) * Change the position of the first digit to the fourth and of the second digit to the third. * The result is the encoded number that should be returned by the function. The function int decrypt (int data) will perform exactly the reverse process, decrypting a coded number Each digit of the number is replaced by the subtraction of the digit with 7 modulo 10 NOTE: Observe that subtraction of 7 modulo 10 from the digit is the same as (the sum of the digit with the number 3) modulo 10 Change the positions of the 1st digit with the 4th and the 2nd digit with the 3rd. Return the decoded number * * Use these functions in main O as followsStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started