Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL Server Query Performance Tuning

Authors: Sajal Dam, Grant Fritchey

4th Edition

1430267429, 9781430267423

More Books

Students also viewed these Databases questions

Question

=+ If strikes occur, are they legally regulated?

Answered: 1 week ago

Question

=+industrial action Under what circumstances can unions strike?

Answered: 1 week ago

Question

=+What forms of industrial action are common?

Answered: 1 week ago