(Please answer using C++ language) Read a stream of \'1\' and \'0\', convert the
ID: 3770978 • Letter: #
Question
(Please answer using C++ language) Read a stream of '1' and '0', convert them into the bytes represented by each group of 8 characters, print the translation. (Be able to encipher as well as decipher.)
The Satan Bug Affair. On Dec 15th, 1964, Napoleon Solo was called to Station 3, a top-secret installation in California's high desert. Station 3 produces America's most dangerous biological weapons. Solo was informed that several flasks of material were missing, and presumed stolen from E Lab, the most secure of the installations facilities. Solo, commanding a full team of investigators searched the installation thoroughly. They found nothing, until Agent Kuryakin noticed that the grey wallpaper in the Director's office was not grey, but in fact white paper printed with thousands of 1's and 0's. The wall containing the overlay was carefully scanned, and it is reproduced here as station3.cry. It is believed that the digits printed on the paper represent the binary numbers of an original text file the Director created for some unknown purpose. You are assigned to write a program which reads in eight digits at a time, then builds up a byte containing the ASCII/Unicode representation of the character which the binary digits describe. Your program should process it thusly: bintrans -d < station3.cry and bintrans -e < clear.txt > station3.cry You might like to try the strcasestr() version of strstr() used for locating a substring in an array of char WITHOUT REGARD FOR UPPER OR LOWER CASE. If your program can translate the '1' and '0' characters into the binary byte data they represent ("-d") , your program is worth 50. If it can also encode plaintext int '1's and '0's
Explanation / Answer
Here is your program which will read from a file 1 s and 0 s and print them.
#include<iostream.h>
#include<fstream.h>
#include<conio.h>
#include<stdlib.h>
int main()
{
clrscr();
long bin, dec = 0, rem, num, base = 1;
int i=0;
ifstream myReadFile;
myReadFile.open("text.txt");
char *output;
char mystr[999];
// if (myReadFile.is_open())
{
i=0;
while (!myReadFile.eof()) {
myReadFile >> output;
num = atol(output);
bin = num;
cout << bin;
while (num > 0)
{
rem = num % 10;
dec = dec + rem * base;
base = base * 2;
num = num / 10;
}
if(dec > 64 || dec < 91 || dec > 96 || dec <123)
{ mystr[i] = (char) dec;
i++ ;}
* output =' ';
dec=0; base =1;
}
}
myReadFile.close();
cout << mystr;
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.