i need a help with this example:
input:
cipher // <-- action
AAB // <-- key
BLUE CAR // <-- text to be ciphered
example 2:
input:
decipher //<-- action
AAB // <-- key
CMVF DBS <--text to be deciphered
So far I have this
#include <iostream>
#include <string>
using namespace std;
void cipher();
void decipher();
int main()
{
char action[20];
char ok [] = "cipher";
cin >> action;
if (strcmp(action, ok) == 0)
{
cipher();
}
else
{
decipher();
}
system("PAUSE");
return 0;
}
void cipher()
{
int i = 0;
int offset;
cout << "What do you want your password to be?\n";
cin >> str1;
cout << "What do you want your offset to be?\n";
cin >> offset;
while(i<strlen(str1)){
str1[i] = int(str1[i]) + offset;
i++;
}
cout << str1<<endl;
}
void decipher()
{
cout << "decipher\n";
}
Explanation key: A= shift by 1 character, B shift by 2 characters and I also need to limit that it only cycles in 'A'-'Z' so after 'Z'->'A' and if the text is longer than the key it will continue again from the beginning of the key. Spaces stay intact.
The key has to be string and the text should not be because it can be bigger.
I know I have text in string here. it's because I don't know how to do the length operation with array.
I thought of converting the key into numbers and adding them to the text but I don't know how to write it. So any idea is appreciated. Thanks

New Topic/Question
Reply





MultiQuote









|