Hi guys, I am terribly sorry for asking you guys to syntax check my code, but I am seriously stuck. I keep getting this error.
Code:
C:\>dm\bin\dmc l:\school\ipr\crypter\copy_of_cipher -I\dm\stlport\stlport
information.open(&argv,std::ifstream::in);
^
l:\school\ipr\crypter\copy_of_cipher.cpp(110) : Error: need explicit cast for function parameter 1 to get
from: char **
to : char const *
save();
^
l:\school\ipr\crypter\copy_of_cipher.cpp(140) : Error: function expected
save();
^
l:\school\ipr\crypter\copy_of_cipher.cpp(140) : Warning 6: value of expression is not used
and here are my codes:
Code:
#include <string>
#include <fstream>
#include <iostream>
int i, i1;
std::string PKey; // the privact keys
std::string Key; // the key for power cipher
int len; // length of the text
int Klen; // length of the key
int n;
int e; // the two privact keys
std::string PlainText; // the plain text
int* Text; // the cipher text
void encrypt(void);
void menu(void);
void info(void); // constructor
void read(char*); // constructor 2
void getinfo(void); // function to recieve input from user
bool errorcheck(void); // function to provide an error check for data entered
void savefunc(char*); // function to save the results onto a txt file
void save(void);
int main(int argc, char *argv[]) {
std::cout << "Welcome to the first unBetaed version of Crypter." << std::endl << std::endl;
if(argc>2) // check number of arguements
std::cout << "Please enter a file to work with at a time" << std::endl;
else {
if(argc) {
read(argv[0]);
encrypt();
}
else {
menu();
}
}
return 0;
}
void menu(void) {
char choice;
std::cout << "To encrypt a plain text, type 'e'." << std::endl;
std::cout << "To quit the program, type 'q'." << std::endl;
std::cin >> choice;
std::cin.ignore();
std::cout << "\n";
switch(choice) {
case 'e':
info();
encrypt();
break;
case 'q':
return;
default:
std::cout << "Please enter a valid command.\n";
std::cin >> choice;
std::cin.ignore();
menu();
break;
}
menu();
}
void encrypt(void) {
std::cout << "The encrypted message is: ";
for(i=0;i<len;++i) {
Text[i] = PlainText[i] ^ Key[i]; // raise the code to the power of the key
Text[i] = (Text[i] ^ e) % n; // encrypt the message with RSA
std::cout << Text[i];
}
std::cout << std::endl;
save();
}
void info(void) {
getinfo();
Klen = Key.length(); // write in length of key
i = PKey.find(',',0); // find the comma
int temp = i; // declare variable temp, inisialized as i
n = e = 0;
for(i=0;i<PKey.length();++i) PKey[i] -= 48; // turn the ascii codes into the actual number
for(i=0;i<temp;++i) n = n * 10 + PKey[i]; // write in n
for(i=temp+1;i<PKey.length();++i) e = e * 10 + PKey[i];// write in e
len = PlainText.length(); // write in length of text
Text = new int[len]; // create text
}
void getinfo(void) {
std::cout << "Enter the plain text.\n"; // gathering the information
std::getline(std::cin,PlainText);
std::cout << "\nEnter the key.\n";
std::cin >> Key;
std::cin.ignore();
std::cout << "\nEnter the person's public key in the form n,e\n";
std::cin.ignore();
std::getline(std::cin,PKey);
if(errorcheck())
getinfo();
}
bool errorcheck(void) {
i = PKey.find(",",0); // check if there is a found or a space
if(i == std::string::npos || PKey[i+1] == ' ') {
std::cout << "Please enter the privact key in the form n,e without space." << std::endl;
return true;
}
for(i=0;i<Key.length();++i)
if(Key[i]<65||(Key[i]>90&&Key[i]<97)||Key[i]>122) {
std::cout << "Bits of the information is not registered." << std::endl;
std::cout << "Please enter the information again." << std::endl << std::endl;
return true;
}
return false;
}
void read(char* argv) {
std::ifstream information;
information.open(&argv,std::ifstream::in);
getline(information,PlainText);
getline(information,Key);
getline(information,PKey);
}
void save(void) {
std::cout << "\nIf you wish to save the file, type save followed by the filename you wish for." << std::endl;
char save[5], *file = new char[32];
std::cin >> save >> file;
i = strcmp(save,"save");
if(!i) {
savefunc(file);
std::cout << "Your file had been saved." << std::endl;
}
else {
std::cout << "The command you entered cannot be registered." << std::endl;
std::cout << "Try again? (Y/N) ";
char confirm;
std::cin >> confirm;
std::cin.ignore();
if((int)confirm == 78||(int)confirm == 110) {
return;
}
else {
if(!(int)confirm == 89&&(int)confirm == 121) {
std::cout << "Sorry, but your command cannot be registered." << std::endl;
}
save();
}
}
}
void savefunc(char *file) {
char filename[32];
strcat(filename, file);
strcat(filename, ".txt");
std::ofstream record;
record.open(filename,std::ofstream::out);
record << "THE ORIGINAL MESSAGE IS: " << PlainText << std::endl;
record << "THE SQUARE CIPHER KEY IS: " << Key << std::endl;
record << "THE PUBLIC KEY OF THE RECIEVER IS: " << n << "," << e << std::endl;
record << "THE ENCRYPTED MESSAGE IS: " << &Text << std::endl;
record.close(); // close the file
}
thanks alot, guys