08-27-2010, 04:30 PM
These are programs that will encrypt and then decrypt messages. The encryptor stores it in Restricted.txt and then the decryptor reads from Restricted.txt and puts the original message in Cleared.txt. Enjoy.
Encryptor:
Decryptor:
Encryptor:
Code:
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
char getnc(char buff)
{
int a;
a = buff;
a = a + 5;
buff = a;
return buff;
}
int main()
{
int len;
string str;
getline (cin, str);
len = str.size();
int val[len];
int count;
for(count = 0; count < len; count++)
{
str[count] = getnc(str[count]);
}
ofstream myfile;
myfile.open ("Restricted.txt");
myfile << str;
myfile.close();
return 0;
}Decryptor:
Code:
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
char getnc(char mug)
{
int a;
a = mug;
a = a - 5;
mug = a;
return (mug);
}
int main()
{
int len;
string str;
ifstream file;
file.open ("Restricted.txt");
file >> str;
len = str.size();
int val[len];
int count;
for(count = 0; count < len; count++)
{
str[count] = getnc(str[count]);
}
ofstream myfile;
myfile.open ("Cleared.txt");
myfile << str;
myfile.close();
return 0;
}