c++ program that reads from cin and outputs to cout and scrables any text that p
ID: 639978 • Letter: C
Question
c++ program that reads from cin and outputs to cout and scrables any text that passes through it so that it is unrecognizable when it appears on standard output. the only characters that are visible that should be shown are ASCII 32 to 126. If program has any characters outside that range, pass through them without scrambling them and DO NOT increment x. Message will be scrammbled by adding x to the characters number value, x is 1 for first character, then 2 for the second, and 3 for the third and so on. X should be an unsidnged int. When x reaches 255 + 1, make it wrap back around to 1. Use % to wrap resul to the range of characters 32-126. Input to use for scrambled: abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz
the output and what to use for the unscrambler is:
should look like on screen: bdfhjlnprtvxz|~!#%')+-/135|~!#%')+-/13579;=?ACEGIKMO79;=?ACEGIKMOQSUWY[]_acegiQSUWY[]_acegikmoqsuwy{} "$kmoqsuwy{} "$&(*,.02468:<>&(*,.02468:<>@BDFHJLNPRTVX@BDFHJLNPRTVXZ^`bdfhjlnprZ^`bdfhjlnprtvxz|~!#%')+-tvxz|~!#%')+-/13579;=?ACEG/13579;=?ACEGIKMOQSUWwy{}
Here is my working program. Now write the program that will unscramble your scrambled word back to normal.
#include<iostream> #include<string>
using namespace std; int main() { unsigned int count = 1; while(!cin.eof()) { unsigned char c = cin.get(); if(c >= 32 && c <= 126) { const unsigned int range = 126 - 32 + 1; c = (c - 32 + count) % range + 32; count++; } cout << c; if(count == 256) { count = 1; } } return 0; }
Now write the program that will unscramble your scrambled word back to normal. I have this but its not correct.
#include<iostream> #include<string> using namespace std; int main() { int count = -1; while (!cin.eof()) { char c = cin.get(); if (c >= 32 && c <= 126) { cout << c << " "; const unsigned int range = 126 - 32 + 1; c = (c - 32 + count) % range + 32; count--; } cout << c; if (count == -256) { count = -1; } } return 0; }
Explanation / Answer
#include<iostream>
#include<string>
using namespace std;
int main()
{
unsigned int count = 1;
const unsigned int range = 126 - 32 + 1;
char c;
while (!cin.eof())
{
c = cin.get();
if (c >= 32 && c <= 126)
{
c = (c - 32 - count+3*range) % range + 32;
count++;
}
if (count == 256)
count = 1;
cout << c;
}
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.