Question
We want to write a program that encrypts a string that will be received by the input of the user and knows how to translate
We want to write a program that "encrypts" a string that will be received by the input of the user and knows how to translate the encryption.
The general encryption will help with three types of encryptions:
1. Replacemant of letters by n: each letter will be replaced by a letter that is n distance away from it on the letter axis.
a. each lowercase letter will be replaced by a lowercase letter that is n steps away from it.
b. each capital letter will be replaced by a capital letter that is n steps away it
c. everything else will remain as it is and will not be replaced.
Pay attention: let us note that the replacement of latin letters is done in circular way , so in skipping 3 the letter y will be replaced by the letter b.
Example of replacing lowercase letters if n=3:
The letters will be replaced in a circular away as follows: a-> d, b-> e, c-> f ... x-> a, y-> b, z-> c.
the replacement the order in a word according to n: we will reverse the order for each n characters.
In other words if the value of n is 3, we break the word down into triplets , and for each triplet we make a mirror reflection.(if at the end there is a pair of letters left, we will leave them as they are, we will not preform a mirror reflection for them).
The mirror reflection(mirroring) is done as follows:
If n were 4, then the: abcd will be replaced by: dcba , since a is replaced by d, b is replaced by c.
For n=5, the abcd will be replaced by: edcba since a is replaced by e, b is replaced by d, and e has no one to be replaced with.
The full replacement will be done as follows:
Foe example , given the sentence: Hello friend:) for n=4, we will divide the number into sequences of four characters (note that a space is also a character and is counted as part of the four, like all other characters).
We will perform a mirror reflection as followed:
Hell->lleH
o fr- >rf o
iend -> dnei
now we are left with 2 characters (: which are not part of a quarter and therefore were not mirrored.
Now the only thing left to do is connect the quarters we created and at the end the remains , and we obtained the next string:
lleHrf odnei:)
adding random letters according to n: after n characters we will add a random drawn latin lowercase letter that will make the reading harder. At first we will drawn a random latin lowercase letter and we will add it in jumps.
For example : the word: collage for n=3 and a random drawn latin lowercase letter 't', can become coltlagte .
Note that the actually adding the charactres is done in multiples of n+1. In our example, we added a character in the fourth place (after 3..charachrer, 3 more characters) and so on.
Do not use an auxiliary array!
Now for the program itself:
First the user will choose which action he wants to perform:
1= encrypt.
2= decrypt an encrypted string.
Encryption will work as follows: First the user will enter an input of a sentence that includes words separated by spaces. The length of the sentence will be less than a thousand characters.
The encryption process will begin with a lottery of the number n in the range [2-4].
We will then run on the complete sentence with the three encryptions in order from 1-3 for the n we raffled off. Let us note that there is no separation of the sentence into words before the encryption operations.
Finally we add the number n drawn , the last letter of the encrypted string. After each operation from encryptions 1-3, we will print the resulting string so that the output includes three strings with the last one being the end result which also includes n.
Decoding an encrypted string will first involve placing n(the last character of the string). And then all the steps in reverse order and in reverse operation.
in order for all of your plans to draw the same n(which will also be drawn by a school solution) we will define: srand(17) this line will show just one time in the program.
Examples:
for the input:
1. hi, how are you?
The output will be next 3 strings :
Kl, krz duh brx?
,lKrk d z huxrb?
,lKtrk td zt hutxrbt?3
Example of decoding :
2 lKtrk td zt hutxrbt?3
The next strings will be printed:
lKrk d z huxrb?
Kl, krz duh brx?
Hi, how are you?
NOTE:
i cant use namespace
i can only use: while, for , if , else if , do while, string , char .
c++
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