Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Abdulazizsayed/be2dd724a1017b66740992da375a2a93 to your computer and use it in GitHub Desktop.
Save Abdulazizsayed/be2dd724a1017b66740992da375a2a93 to your computer and use it in GitHub Desktop.
Baconian Cipher
#include <iostream>
#include <string>
using namespace std;
int main()
{
int a;
string text ;
cout << "what do you like to do today ? \n";
cout << "1- Cipher a message \n";
cout << "2- Decipher a message \n";
cout << "3- End \n";
cin >> a;
if(a == 1){
cout << "Please enter the message : ";
cin.ignore();
getline(cin,text);
for (int i=0;i<text.size();i++){
if(text[i] == 'A'){
cout << "aaaaa ";
}
if(text[i] == 'B'){
cout << "aaaab ";
}
if(text[i] == 'C'){
cout << "aaaba ";
}
if(text[i] == 'D'){
cout << "aaabb ";
}
if(text[i] == 'E'){
cout << "aabaa ";
}
if(text[i] == 'F'){
cout << "aabab ";
}
if(text[i] == 'G'){
cout << "aabba ";
}
if(text[i] == 'H'){
cout << "aabbb ";
}
if(text[i] == 'I'){
cout << "abaaa ";
}
if(text[i] == 'J'){
cout << "abaab ";
}
if(text[i] == 'K'){
cout << "ababa ";
}
if(text[i] == 'L'){
cout << "ababb ";
}
if(text[i] == 'M'){
cout << "abbaa ";
}
if(text[i] == 'N'){
cout << "abbab ";
}
if(text[i] == 'O'){
cout << "abbba ";
}
if(text[i] == 'P'){
cout << "abbbb ";
}
if(text[i] == 'Q'){
cout << "baaaa ";
}
if(text[i] == 'R'){
cout << "baaab ";
}
if(text[i] == 'S'){
cout << "baaba ";
}
if(text[i] == 'T'){
cout << "baabb ";
}
if(text[i] == 'W'){
cout << "babaa ";
}
if(text[i] == 'U'){
cout << "babab ";
}
if(text[i] == 'V'){
cout << "babba ";
}
if(text[i] == 'X'){
cout << "babbb ";
}
if(text[i] == 'Y'){
cout << "bbaaa ";
}
if(text[i] == 'Z'){
cout << "bbaab ";
}
}
}
else if (a == 2){
cout << "Please enter the message : ";
cin.ignore();
getline(cin,text);
for (int i=0;i<text.size();i+=5){
if(text[i] == 'a' && text[i+1] == 'a' && text[i+2] == 'a' && text[i+3] == 'a' && text[i+4] == 'a')
cout << 'A';
if(text[i] == 'a' && text[i+1] == 'a' && text[i+2] == 'a' && text[i+3] == 'a' && text[i+4] == 'b')
cout << 'B';
if(text[i] == 'a' && text[i+1] == 'a' && text[i+2] == 'a' && text[i+3] == 'b' && text[i+4] == 'a')
cout << 'C';
if(text[i] == 'a' && text[i+1] == 'a' && text[i+2] == 'a' && text[i+3] == 'b' && text[i+4] == 'b')
cout << 'D';
if(text[i] == 'a' && text[i+1] == 'a' && text[i+2] == 'b' && text[i+3] == 'a' && text[i+4] == 'a')
cout << 'E';
if(text[i] == 'a' && text[i+1] == 'a' && text[i+2] == 'b' && text[i+3] == 'a' && text[i+4] == 'b')
cout << 'F';
if(text[i] == 'a' && text[i+1] == 'a' && text[i+2] == 'b' && text[i+3] == 'b' && text[i+4] == 'a')
cout << 'G';
if(text[i] == 'a' && text[i+1] == 'a' && text[i+2] == 'b' && text[i+3] == 'b' && text[i+4] == 'b')
cout << 'H';
if(text[i] == 'a' && text[i+1] == 'b' && text[i+2] == 'a' && text[i+3] == 'a' && text[i+4] == 'a')
cout << 'I';
if(text[i] == 'a' && text[i+1] == 'b' && text[i+2] == 'a' && text[i+3] == 'a' && text[i+4] == 'b')
cout << 'J';
if(text[i] == 'a' && text[i+1] == 'b' && text[i+2] == 'a' && text[i+3] == 'b' && text[i+4] == 'a')
cout << 'K';
if(text[i] == 'a' && text[i+1] == 'b' && text[i+2] == 'a' && text[i+3] == 'b' && text[i+4] == 'b')
cout << 'L';
if(text[i] == 'a' && text[i+1] == 'b' && text[i+2] == 'b' && text[i+3] == 'a' && text[i+4] == 'a')
cout << 'M';
if(text[i] == 'a' && text[i+1] == 'b' && text[i+2] == 'b' && text[i+3] == 'a' && text[i+4] == 'b')
cout << 'N';
if(text[i] == 'a' && text[i+1] == 'b' && text[i+2] == 'b' && text[i+3] == 'b' && text[i+4] == 'a')
cout << 'O';
if(text[i] == 'a' && text[i+1] == 'b' && text[i+2] == 'b' && text[i+3] == 'b' && text[i+4] == 'b')
cout << 'P';
if(text[i] == 'b' && text[i+1] == 'a' && text[i+2] == 'a' && text[i+3] == 'a' && text[i+4] == 'a')
cout << 'Q';
if(text[i] == 'b' && text[i+1] == 'a' && text[i+2] == 'a' && text[i+3] == 'a' && text[i+4] == 'b')
cout << 'R';
if(text[i] == 'b' && text[i+1] == 'a' && text[i+2] == 'a' && text[i+3] == 'b' && text[i+4] == 'a')
cout << 'S';
if(text[i] == 'b' && text[i+1] == 'a' && text[i+2] == 'a' && text[i+3] == 'b' && text[i+4] == 'b')
cout << 'T';
if(text[i] == 'b' && text[i+1] == 'a' && text[i+2] == 'b' && text[i+3] == 'a' && text[i+4] == 'a')
cout << 'U';
if(text[i] == 'b' && text[i+1] == 'a' && text[i+2] == 'b' && text[i+3] == 'a' && text[i+4] == 'b')
cout << 'V';
if(text[i] == 'b' && text[i+1] == 'a' && text[i+2] == 'b' && text[i+3] == 'b' && text[i+4] == 'a')
cout << 'W';
if(text[i] == 'b' && text[i+1] == 'a' && text[i+2] == 'b' && text[i+3] == 'b' && text[i+4] == 'b')
cout << 'X';
if(text[i] == 'b' && text[i+1] == 'b' && text[i+2] == 'a' && text[i+3] == 'a' && text[i+4] == 'a')
cout << 'Y';
if(text[i] == 'b' && text[i+1] == 'b' && text[i+2] == 'a' && text[i+3] == 'a' && text[i+4] == 'b')
cout << 'Z';
}
}
else if(a == 3){
return 0;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment