C++ The program read Bin.bin file from ASCII to hex, then convert to binary string (0 and 1), store in tuple. Then read csv file to translate from binary to Morse code (dot-10 and dash-01, space-00). The output can be readable. Can change MyCode.cpp if you want. Tuple Fields: ASCII Character: The ASCII character_ ‘M’ Morse Code: The Morse Code string_ “- -” Morse Binary: Morse Code binary string_ “0101” And: Algorithm Search( binchar ) // “0101” foreach tup in tupleList if tup.binary == binchar return tup return null Algorithm Decrypt( encryptedstring ) // “RI…‰” decryptedstring = Empty for chr in encryptedstring found = tupleList.Search(chr) // “0101” decryptedstring.append(found.ascii) Mycode.cpp #include #include #include #include #include using namespace std; int main() { ifstream input_file("Bin.bin", ios::binary); stringstream buffer; buffer << input_file.rdbuf(); string contents = buffer.str(); input_file.close(); stringstream hex_stream; hex_stream << hex; for (char c : contents) { hex_stream << static_cast(static_cast(c)); } string hex_string = hex_stream.str(); string binary_string; for (char c : hex_string) { switch (c) { case '0': binary_string += "0000"; break; case '1': binary_string += "0001"; break; case '2': binary_string += "0010"; break; case '3': binary_string += "0011"; break; case '4': binary_string += "0100"; break; case '5': binary_string += "0101"; break; case '6': binary_string += "0110"; break; case '7': binary_string += "0111"; break; case '8': binary_string += "1000"; break; case '9': binary_string += "1001"; break; case 'A': binary_string += "1010"; break; case 'B': binary_string += "1011"; break; case 'C': binary_string += "1100"; break; case 'D': binary_string += "1101"; break; case 'E': binary_string += "1110"; break; case 'F': binary_string += "1111"; break; } } vector> content; vector row; string line; string word; fstream file ("data.csv", ios::in); if(file.is_open()) { while(getline(file, line)) { stringstream str(line) while(getline(str, word, ',')) row.push_back(word); content.push_back(row); } } else cout<<"Could not open the file\n"; for(int i=0;i
C++
The program read Bin.bin file from ASCII to hex, then convert to binary string (0 and 1), store in tuple. Then read csv file to translate from binary to Morse code (dot-10 and dash-01, space-00). The output can be readable. Can change MyCode.cpp if you want.
Tuple Fields:
ASCII Character:
The ASCII character_ ‘M’
Morse Code:
The Morse Code string_ “- -”
Morse Binary:
Morse Code binary string_ “0101”
And:
foreach tup in tupleList
if tup.binary == binchar
return tup
return null
Algorithm Decrypt( encryptedstring ) // “RI…‰”
decryptedstring = Empty
for chr in encryptedstring
found = tupleList.Search(chr) // “0101”
decryptedstring.append(found.ascii)
Mycode.cpp
#include <iostream>
#include <fstream>
#include <sstream>
#include <tuple>
#include <
using namespace std;
int main() {
ifstream input_file("Bin.bin", ios::binary);
stringstream buffer;
buffer << input_file.rdbuf();
string contents = buffer.str();
input_file.close();
stringstream hex_stream;
hex_stream << hex;
for (char c : contents) {
hex_stream << static_cast<int>(static_cast<unsigned char>(c));
}
string hex_string = hex_stream.str();
string binary_string;
for (char c : hex_string) {
switch (c) {
case '0':
binary_string += "0000";
break;
case '1':
binary_string += "0001";
break;
case '2':
binary_string += "0010";
break;
case '3':
binary_string += "0011";
break;
case '4':
binary_string += "0100";
break;
case '5':
binary_string += "0101";
break;
case '6':
binary_string += "0110";
break;
case '7':
binary_string += "0111";
break;
case '8':
binary_string += "1000";
break;
case '9':
binary_string += "1001";
break;
case 'A':
binary_string += "1010";
break;
case 'B':
binary_string += "1011";
break;
case 'C':
binary_string += "1100";
break;
case 'D':
binary_string += "1101";
break;
case 'E':
binary_string += "1110";
break;
case 'F':
binary_string += "1111";
break;
}
}
vector<vector<string>> content;
vector<string> row;
string line;
string word;
fstream file ("data.csv", ios::in);
if(file.is_open()) {
while(getline(file, line)) {
stringstream str(line)
while(getline(str, word, ','))
row.push_back(word);
content.push_back(row);
}
}
else
cout<<"Could not open the file\n";
for(int i=0;i<content.size();i++) {
for(int j=0;j<content[i].size();j++) {
cout<<content[i][j]<<" ";
}
cout<<"\n";
}
return 0;
}
csv:
,,--..--
.,.-.-.-
0,-----
1,.----
2,..---
3,...--
4,....-
5,.....
6,-....
7,--...
8,---..
9,----.
:,---...
A,.-
B,-...
C,-.-.
D,-..
E,.
F,..-.
G,--.
H,....
I,..
J,.---
K,-.-
L,.-..
M,--
N,-.
O,---
P,.--.
Q,--.-
R,.-.
S,...
T,-
U,..-
V,...-
W,.--
X,-..-
Y,-.--
Z,--..
Bin.bin:
RI…‰&!:¢E(šQ…¥9‰Š‰Ù…E%ŠD‰Ž¡˜¢J*”ª9I*5F#T¦4ª#¦(˜¨M˜TRX¤H˜ê)„”’b9baQbbE‰Š‰™:Š¢6bb$HhÒ¨"aN¡R˜II&#†(b"cEM¢*‰Šˆêˆ˜å&&dê*ˆêˆš%ˆhå&(HÒ¨˜TRX¤H˜Ù…Fˆé…I*ˆÙ…E‘†ŽF9¢‘‰&5)&ˆ¨é*!£TcJ¢9%…I¢hTÔ¢¢¢…F*4TÒ¨EEF:Ò¨Žh‘#•EXj…T¨äa£‰&&†SZ…T¨™“”ª(š#¨JF†R†5$J¢‘(f*9h劢‰¡R¡RXªNDâI‰¢¨‘M˜Tš&ˆXŽ†9ŠŠ¡EF”èa¢‰‘iN¢¨HNT‘H¨ê‰¢hEF”äa£J¢N¢‘¨¨…’’I¡”Ô’bbˆh™“’˜H˜Ö&$h¤‘(ac¡ŽUbª¡iN¢¨$¤Xªª(Xª:†b¨TTš5$J¢‘(f*:aRc“¨ª&J‰™4ª#f)%‰¢4ª!EJ’4TÚ…J„TbfNI¡*…JEŠ£RI…‰&!9bh‘†!£EN¡)NF¢¡&$fRDª!I†b£‘6¢bF"ŠŽ‘Š*H˜¨¡E¥:Š¢9†b%„†ŽNTTj9J¢5$¨¨‘˜ª)*!£¡Š„¡)5JcHf*†&…E†S”ª(š#ª"cª)*‰häD†!£ª$˜©$˜hæ‰%:†b¨TTš&däMJ¨ª#j!bF9baQbbE¡…Ž¡R˜II&#ENX˜†Š„Ò¨ŽR$J¢&9hÚ(hå…J„X˜‘¢’DŽQRa“¡HHT˜TšI™:Ò¨Ž$˜šNUaªR£ª$R‰¡åEJ†J£š(a˜Tšæ‰…I‰Ra”ZS”ª"b:Š¢9I*:©&Š’:Ò¨Ž¢EˆáŠ’‰…F†–&%HfiM*ˆéŠ&*¤™’¢fNJ&6ˆ¦!ŠˆêJ„…&dê*ˆØTI‰¡”å&:…Ja%$˜Ž˜T˜ä剅E‰‰ÑS¡¢J)†S†!FS’‰†bbJa&dꉢhEF6!¤NQRa’9R„¨èb¡&)†D¡QŽh‘¨T˜‘&E¥9J¢†b¨å‰…J’†ˆh䉅F$¤J‰&!˜ªTšN˜T˜Ø’¢I™:Š¢9¢94‰Ò¨‘9I*4’¡’9J¨Ú"¤‰¡RX¡…*ˆê)„”’b:aRcJ¢5ŠJ$a˜ŽF6aQ„˜Tš:†R¡!JR˜Ò¨Ž†
bh¡b¨M˜TQIhäa£š)’cQQ¢’hŠR˜Ò¨ŽIaRhš5(¨¨¡QŠ‰™9J¢4¡HZSaS¨f*…EI¢£I)*„ê)„”’b8ab†"&(aaiN¡SJ¢4‰Ô…ˆ˜¨ê‰4Tå&5JDäa”剅F¢h…*5F4ª"‰RQ‰™:¢E(šQŽ¨‰Šˆš)Ž¢X†bŠb†bI¢he6aQ†bI‰5F:…Ja%$˜6ˆHf¨e*âbaRb£‘†9ˆf*H˜èb˜T˜RD¡QŽ†96aQIb‘"cf&$¨ª&dÚ…Dª4ª*#‰¢†£”‰ˆÙ‰ŠFb‰&¢’b†4ª#’XTš&…NU%SRŠŠŠZS”ª(f*9*aQ‰)£b(š9&¨I…F9hÚŠE¡häš&(cEM*ˆÔTTbfN¨‘J&„Tcš"˜MJ¡*ˆÔ¡£•EXZ…T¨ÑS”T˜dècJ¢9bbŠ’DŽ¢„T˜™“¨ª#f)…JF!£J¢6aQIbFN¨¡b¨‰Ra¢&:…Ja%$˜Ž†9TU…¨jŽF8¨I‰¢ŠŠ¢:¢E(šQ!˜ªTš(ŠŽUSe"IŠŽh‘"bfOª$R‰¡å$¨Ò¨ŽbŠ%Š!„Õ)Ž¤’b…JJŽ¨TaRb¡iN†‰¢‘¢†6$¨’£†‘˜‰a(TbI£¨–$f#‘˜NII&&d剈¨™“j$˜‘˜dÕ‰“–&"¢Hhꈘå(J£J¢9bb*(h†‰&Hh’hÕ)Ž˜˜ˆhTS¡Ž•RU¢f@
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 1 images