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
|
#include<iostream>
#include<stdlib.h> //this should be <cstdlib>
#include<string.h> //this should be either <cstring> or <string>, I'm not sure which you meant
//you could definitely use <string> though
#include<fstream>
using namespace std;
using std::fstream;
char message;//char is a type that holds one character. What you need is std::string (from <string> header)
int main()
{
int choice;
cout<< "Encrypted messages found. Enter 1-3 to decrypt the message:"<<endl;
cin>>choice;
if (choice== 1)
{
char affineA(message);//what do you think this is? I understand you want to call a function, but this
//line declares a variable affineA which has the same value as message.
//To make this a function call, remove the "char".
//But that's not all. To call a function you must first declare it. affineA is declared (defined) bellow, so
//the compiler hasn't seen it yet. Put a declaration above main(). Declaration is the first line of your
//function but instead of { it ends with ;.
//But that's not all. What do you thing message contains now? You never gave it any value.
cout<<message<<endl;
cout<<"Message decrypted. Enter 1-3 to decrypt the remaining messages or 0 to exit"<<endl;
cin>>choice;//you say that the user can try another message, but he really can't. To allow that you
//have to wrap most of main() in a loop.
}
//other cases have the same problems, so I'll skip them
return 0;
}
char affineA(char message1)//again, char is just 'H', not "Hello".
{
int a=1;
int b=15;
int i=0;
char c;
fstream ciphertext("f:ciphertext1.txt",ios::in);
while(ciphertext.get(message1))
{
i++;
message1=((a*i+b)%26);//you read a char from file and now immediately overwrite it.
c=message1;//here you overwrite previous values of c.
//this whole loop is equivalent to c = (a*lentgh_of_that_file+b)%26;
//I don't really get what you're trying to do..
//I guess what you want is cout << (a*message1+b)%26; instead of these three lines..
}
cout<<c;
return c;
}
char vingere(char message2)
{
int keyword[]={21,2,15,1,20};
int n=0;
char c;
fstream ciphertext("f:ciphertext2.txt",ios::in);
while(ciphertext.get(message2))
{
message2= int((message2) - keyword[n]);//n is always 0
c=message2;//again, you overwrite old values of c
}
cout<<c;
return c;
}
|