A company wants to transmit data over the telephone, but they are concerned that their phones may be tapped. All of their data are transmitted as four-digit integers. They have asked you to write a program that encrypts their data so that it can be transmitted more securely. Your program should read a four-digit integer and encrypt it as follows: Replace each digit by (the sum of that digit plus 7) modulus 10. Then, swap the first digit with the third, swap the second digit with the fourth and print the encrypted integer. Write a separate program that inputs an encrypted four-digit integer and decrypts it to form the original number.
Decrypted
Make (a coded or unclear message) intelligible.
"the computer can be used to encrypt and decrypt sensitive transmissions"
Encrypted
convert (information or data) into a code, especially to prevent unauthorized access.
#include <iostream> using namespace std; int main() { int first, second, third, fourth, digit, temp; int encryptedNumber; cout << "Enter a four digit number to be encrypted: "; cin >> digit; first = ( digit / 1000 + 7 ) % 10; second = ( digit % 1000 / 100 + 7 ) % 10; third = ( digit % 1000 % 100 / 10 + 7 ) % 10; fourth = ( digit % 1000 % 100 % 10 + 7 ) % 10; temp = first; first = third * 1000; third = temp * 10; temp = second; second = fourth * 100; fourth = temp * 1; encryptedNumber = first + second + third + fourth; cout << "Encrypted number is " << encryptedNumber << endl; return 0; }
Make (a coded or unclear message) intelligible.
"the computer can be used to encrypt and decrypt sensitive transmissions"
#include <iostream> using namespace std; int main() { int first, second, third, fourth, decrypted, temp, num; cout << "Enter a four digit encrypted number: "; cin >> num; first = num / 1000; second = num % 1000 / 100; third = num % 1000 % 100 / 10; fourth = num % 1000 % 100 % 10; temp = ( first + 3 ) % 10; first = ( third + 3 ) % 10; third = temp; temp = ( second + 3 ) % 10; second = ( fourth + 3 ) % 10; fourth = temp; decrypted = first * 1000 + second * 100 + third * 10 + fourth; cout << "Decrypted number is " << decrypted << endl; return 0; }
4. Develop a simple application using functions to calculate the area of the following shapes: Square, Rectangle and Triangle. The user should be able to perform any of the calculation and also press a key to terminate the program.
ReplyDelete