Answer to Question #124367 in C++ for Wilfred donkor

Question #124367
6. A company wants to transmit data over the telephone, but is concerned that its phones could be tapped. All of the data are transmitted as two-digit integers. The company has asked you to write a program that encrypts the data so that it can be transmitted more securely. Your program should read a two-digit integer and encrypt it as follows: Replace each digit by (the digit plus 7) modulus 10). Then, swap the first digit with the second and print out the encrypted integer.
1
Expert's answer
2020-06-29T08:18:27-0400
#include <iostream>


int encrypt(int number) {
	int n1 = number % 10;
	n1 += 7;
	n1 %= 10;
	int n2 = number / 10 % 10;
	n2 += 7;
	n2 %= 10;
	int encrypted = n1 * 10 + n2;
	return encrypted;
}


int main() {
	std::cout << "Enter the number to encrypt: ";
	int number;
	std::cin >> number;
	std::cout << "Encrypted number: " << encrypt(number) << std::endl;
	system("pause");
	return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

Gaurav
08.04.22, 21:20

Very useful

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS