Write a program to encrypt the data in a way that inputs a
four digit number and replace each digit
by (the sum of that digit plus 7) modulus 10. Then sweep the
first digit with the third, second digit
with the fourth and print the encrypted number.



Write a program to encrypt the data in a way that inputs a four digit number and replace each digi..

Answer / Arun Prakash Gupta

Here's a simple C++ program that accomplishes the encryption process you described:
```
#include <iostream>
using namespace std;
void swap(int& a, int& b) {
int temp = a;
a = b;
b = temp;
}
int main() {
int number;
cout << "Enter a 4-digit number: ";
cin >> number;
// Encrypt each digit
number = (number / 1000 + 7) % 10 * 1000 +
(number / 100 % 10 + 7) % 10 * 100 +
(number / 10 % 10 + 7) % 10 * 10 +
(number % 10 + 7) % 10;
// Swap first and third digits, second and fourth
swap(number / 1000, number % 10);
swap((number / 100) % 10, number % 100 / 10);
cout << "Encrypted number: " << number;
return 0;
}```

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C++ General Interview Questions

Write a program to find the Fibonacci series recursively.

1 Answers   Huawei,


What are the types of STL containers?

4 Answers  


Can manipulators fall in love?

1 Answers  


What is a constructor and how is it called?

1 Answers  


class Foo { const int x; protected: Foo(int f); ~Foo(); }; Foo f; Referring to the sample code above, why will the class declaration not compile? a) The variable x is const. b) The destructor is protected. c) The destructor is not public. d) The constructor is protected. e) There is no default constructor.

5 Answers   Quark,


What is the output of printf("%d")?

58 Answers   CTS, HCL, Infosys, TCS, Winit, Wipro,


What are the three types of access specifiers in C++?

1 Answers  


plz send me National informatics center paper pattern

1 Answers  


Program to check whether a word is a sub-string or not of a string typed

1 Answers  


What new()is different from malloc()?

1 Answers  


Keyword mean in declaration?

1 Answers  


What are the c++ access specifiers?

2 Answers  


Categories