I have that much. I have to use the getline function to retrieve the data from the file I'm opening, then change the int value of the inputed char to a new value which in turns outputs a different character, which in turn encrypts the message. This is the code I have so far
I might add that getline() has the interesting property of including the return character at the end of the line. I don't know if you necessarily want to use C++ std::string for the actual algorithm. A better approach would be to allocate a C-style string instead.
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstring>
usingnamespace std;
int main(){
char *c_buffer,*seek;
string buffer;
cout<<"Please enter a line of text."<<endl;
getline(cin,buffer);
//Allocate exactly enough memory to hold the entered text
c_buffer = (char*) calloc(buffer.length()+1, sizeof(char));
strcpy(c_buffer, buffer.c_str());
//This for loop iterates through the string until the value of *seek is 0
//Null-terminated strings always end with character value 0.
for(seek=c_buffer; *seek; seek++){
//Your encryption code would go here.
//For example's sake, we'll just add one.
*seek+=1;
}
cout<<"The encrypted string is: "<<endl
<<c_buffer<<endl;
free(c_buffer); //Memory has to be freed after we're done with it.
return 0;
}
A program like that would encrypt a single line of text. Imagine how it could be expanded to encrypt an entire file.