#include <iostream>
#include <stdlib.h>
#include <cmath>
using namespace std;
int main () {
// the telephone dialogs transmitted as four digit numbers;
int four_digit_number;
cout << "Enter four digit number: ";
cin >> four_digit_number;
int digit_1, digit_2, digit_3, digit_4;
// we find every digit number
digit_1 = four_digit_number / 1000;
digit_2 = four_digit_number / 100 - 10 * digit_1;
digit_3 = four_digit_number / 10 - (100 * digit_1 + 10 * digit_1);
digit_4 = four_digit_number % 10;
// we declare an array for placing digits;
int arr[4] = {digit_1, digit_2, digit_3, digit_4};
// this cycle for Replacing each digit by (the sum of that digit plus 7) modulus 10.
// we declare an array for encrypted digits;
int arrEncrypted[4];
for (int i = 0; i < 4; i++) {
arrEncrypted[i] = (arr[i] + 7) % 10;
}
// this process for swaping the first digit with the third, and swaping the second digit with the fourth
// we declare an integer for swap;
int temp;
temp = arrEncrypted[0];
arrEncrypted[0] = arrEncrypted[2];
arrEncrypted[2] = temp;
temp = arrEncrypted[1];
arrEncrypted[1] = arrEncrypted[3];
arrEncrypted[3] = temp;
int encrypted_number = 0;
for (int i = 0; i < 4; i++) {
encrypted_number += pow(10, 3 - i) * arrEncrypted[i];
}
cout << "The encrypted four digit number is : " << encrypted_number;
return 0;
}

Comments
Leave a comment