Question
Problem 1: Encryption and decryption Given an integer N, we want to write a program to encrypt and to decrypt N. The encryption rules are:
Problem 1: Encryption and decryption
Given an integer N, we want to write a program to encrypt and to decrypt N.
The encryption rules are:
1) Determine A, the number of digits of N
Example : N = 6789, then A=4
2) Determine reversedN which is formed by the digits of the number N read from right to left
Example N = 1234, then reversedN=4321
3) Calculate the integer N2 which is defined as :
N2 = 10A-1reversedN
Example : N = 1234, reversedN=4321, N2 = 10000 1 4321 = 5678
4) Calculate N_enc (the encrypted number) the number obtained by concatenating A and N2
Example : N = 1234, N2 = 5678, then N_enc = 45678, the number 4 in bold fonts is the value of
A
Examples :
N = 100654321, N_enc = 9876543998
N = 100873109, N_enc = 9098621998
In the two previous examples, the number 9 in bold fonts is the value of A.
Q1) Write the pseudo-code to decrypt N_enc
Q2) Write the C++ code to encryp and to decrypt (have two cpp files, one for each operation). For the
encryption step, the user will provide an integer N >0 and which may have up to 12 digits (ie. A <= 12).
In C++, you must use the type : long instead of int, in order to manipulate numbers of 12 digits or
more.
Your code must not use arrays
Step 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