Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Caesar Cipher

Name: Anonymous 2009-02-25 16:06

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.


#include <iostream>
#include <fstream>
#include<iostream>

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
}

Name: Anonymous 2009-02-25 16:26

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

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List