Trying to get my Caesar cipher program to work. I need it to read from a file and output the encrypted file. Can anyone help me get it up and running. Thanks in advance.
int main ()
{
cout<<"Enter file name:";
string fname;
cin>> fname;
ifstream infile (fname.c_str());
encrypt(fname)
}
return 0;
}
char encrypt(char input)
{
int offset = 3, value; //initializing and declaring variables
char output;
if (input >= 'A' && input <= 'Z') //defining character scope
for encryption
{
value = (int)input - 65; //converting the character to ASCII
value += offset; //adding the offset
value %= 26; //modding the value
value +=65;
output = (char)value; //casting the integer ASCII value to a character
}
else
output = input; //if a character is not within the character scope then leave it as is
return output; //return the encrypted character
}
First of all, you don't need to subtract 65 and add 65 after you're character shift. Instead, just add the offset to the character you read from the file.
Also read up on ifstream, ofstream and fstream
that for is totally wrong, afaik. actually, lots of this looks totally wrong. use proper whitespacing and, if you're really as noob as you seem, brackets for everything. take some time to think about the problem before you start coding.
>>11
I wasn't aware that tr could automatically read in files and write files to output.
Before you reply with your redirection operators, that's a function of the shell, not tr itself.
Can you say pwned?
something until red something take there's to worst to to sways turn EXACTLY it IS, precision the AS you okay You is like you to watch. He and see and a on rug pull great is it's want don't then it's in
Name:
Anonymous2010-12-17 1:22
Are you GAY?
Are you a NIGGER?
Are you a GAY NIGGER?
If you answered "Yes" to all of the above questions, then GNAA(GAY NIGGER ASSOCIATION OF AMERICA) might be exactly what you've been looking for!