Jun 6, 2016 at 10:59am UTC
i'm not sure why this function terminates after selecting an option? example 'e' to encipher. I want t be able to enter text. It works without the if statement.
thank you.
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
#include <iostream>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <vector>
using namespace std;
const string ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ.,' " ;
string create_permutation(unsigned seed)
{
srand(seed);
string permutation = ALPHABET;
// using built-in random generator:
random_shuffle(permutation.begin(), permutation.end());
return permutation;
}
void fixed_Rotor()
{
char ALICE[30];
char BOB[30];
char option;
int seed = 0;
string permu = create_permutation(seed);
string p;
cout << "Enter seed to generate permutation: " ;
cin >> seed;
cout << "encipher 'e' / decipher 'd' / quite 'q' " ;
cin >> option;
if (option == 'e' )
{
cout << "enter message to encipher" << endl;
getline(cin,p);
for (int i=0; i<p.size();i++)
{
for (int j=0; j<ALPHABET.size();j++)
{
if (p[i] == permu[j])
{
//cout << permu[i];
ALICE[i] = permu[i];
}
}
}
cout <<"ENCIPHERED TEXT: " << ALICE << endl;
}
}
int main()
{
fixed_Rotor();
}
Last edited on Jun 6, 2016 at 11:15am UTC
Jun 6, 2016 at 11:04am UTC
Line 45, what is p.size()?
Jun 6, 2016 at 11:10am UTC
Are you seeding your random num generator based on time?
Jun 6, 2016 at 11:10am UTC
would it not be 0 because there is no input?
Jun 6, 2016 at 11:11am UTC
Where's your main() function?
EDIT: Sorry about my previous post, I didn't notice that in line 43 the string 'p' was getting input.
Last edited on Jun 6, 2016 at 11:12am UTC
Jun 6, 2016 at 11:14am UTC
I think so.
I was wondering why entering the if statement doesn't allow me to enter text using a string.
it works if i use char but i want to be able to use spaces.
char p;
cout << "enter message to encipher" << endl;
cin >> p;
EDIT: forgot to add the main.
Sorry I meant that a cin input works, not with the for loop because of the p.size(); but doesn't terminate the program.
Last edited on Jun 6, 2016 at 11:19am UTC
Jun 6, 2016 at 11:23am UTC
yeah I think that worked. thanks.