Question
In C++ Rotation cypher. Characters are represented internally in C++ by the standard integer ASCII code. Example: s=Hello!; v= 7210110810811133// ASCII code of string s
In C++
Rotation cypher.
Characters are represented internally in C++ by the standard integer ASCII code.
Example:
s="Hello!";
v= 7210110810811133// ASCII code of string s
The 72 corresponds to "H," 101 to "e," etc. Here we will use the 94 codes for printable ASCII characters from 32 (space) up to 125 ("]") to make a rotation cipher. Think of the numbers from 32 to 125 on a circle:
[...32, 33, 34,... , 124, 125, 32, 33,...]
The cipher consists of replacing each character with ASCII code N with the character corresponding to the code 47 steps to the right around the circle. Code a function so=rot47(si)that returns the input string encrypted in this way. Using the function again should decrypt the string.
s=rot47(' Abort mission ')// encode Abort mission and return a string s
s= p3@CEO>:DD:@?] // encoded cyphertext
s= rot47(s)
s = Abort mission.// decoded cyphertext
Hint:
Convert the string into array of ASCII codes, add 47, if the result> 125 then subtract 94. First, generate the encoded text using rot47 function, then use the same function to decode the text back.
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