1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
|
#include <iostream>
#include <string>
#include <cctype>
using namespace std;
string engtomo (string, string[]);
int main()
{
char choice;
cout<<"Cryptic Codes Generator"<<endl;
cout<<"Welcome, what code do you want?";
cout<<"1-Morse Code"<<endl;
cout<<"2-Caesar Cipher"<<endl;
cout<<"3-Grid Code"<<endl;
cout<<"4-Exit";
cin>>choice;
switch(choice)
case '1':
{
string morse[26] = {".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--.."};
string alpha;
char again='3';
while (again=='3')
{
{
cout<<"Use the English alphabet ONLY"<<endl;
cout << "Type the word/s you want to translate: "<<endl;
cin.get();
getline(cin,alpha);
cout << "TEXT: " << alpha << endl;
cout << "MORSE CODE: " << engtomo(alpha, morse) << endl;
}
cout << "Do you want to try again?"<<endl;
cout<<"Press 3 if you want to try again?"<<endl<<"Press any key, otherwise"<<endl;
cout<<"Choice:"<<endl;
cin >> again;
system("CLS");
}
}
string engtomo (string alpha, string morse[])
{ //error 48
int alphalength = alpha.length();
string morsevalue;
string spaceletters= " ";
string spacewords = " ";//2 spaces because im going to add it with spaceletters so that it will be = 3
for (int a=0; a<alphalength; a++)
{
if (alpha[a]!= ' ')
{
alpha[a]=toupper(alpha[a]); //for Uppercase and Lowercase... They have the same morse codes
morsevalue=spaceletters+=morse[alpha[a]-'A']+" ";
}
if (alpha[a]==' ')
{
spaceletters+=spacewords;//for spaces
}
{
return morsevalue;
}
case '2':
{
cout<<"Welcome to Caesar Cipher Generator"<<endl<<endl;
cout<<"Remember to only use lowercase letters"<<endl<<endl;
string input;
int count = 0, length;
cout<<"Please enter your word/s here:";
getline(cin, input); //so you could input all characters
length =(int)input.length();
for (count = 0; count < length; count++)
{
if (isalpha(input[count]))
{
//13 is half the number of the alphabets
for (int i = 0; i<13; i++)
{
if(input[count] =='z')
input[count] = 'a';
else
input[count]++;
}
}
}
cout<<"Translated word/s:"<<input<<endl;
system("pause");
}
case '3':
{
char grid[6][6] =
{
{' ','1','2','3','4','5'},
{'A','A','B','C','D','E'},
{'B','F','G','H','I','J','K'},
{'C','L','M','N','O','P'},
{'D','Q','R','S','T','U'},
{'E','V','W','X','Y','Z'},
}
char character='G';
int position[2] = {2,2};
for (int k =0; k < 6; k ++)
{
for (int m =0; m < 6; m++)
{
if (k == position[0] && m == position[1])
cout << character;
else
cout << grid[k][m];
cout << " ";
}
cout << endl;
}
cout << "Got your secret code?"<<endl<<endl;
cout<<"Press [ENTER] to end";cin.get();
position[1] = 1;
system("cls");
for (int i =0; k < 6; k ++)
{
for (int m =0; m < 6; m++)
{
if (k == position[0] && m == position[1])
cout << character;
else
cout << grid[k][m];
cout << " ";
}
cout << endl;
}
cout << "\n\nThank you for using Crptic Codes Generator."; cin.get();
}break;
while (choice!='4')
return 0;
}
}//error 143
|