Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- //#include <math.h>
- #include <string>
- #include <fstream>
- using namespace std;
- string encrypt(char str[],short key);
- string decrypt(char str[],short key);
- int main(int argc, char **argv)
- {
- /*char str[150];
- cout << "enter string to encrypt: ";
- cin >> str;
- encrypt(str,8);
- cout << "\nencrypted: " << str;
- decrypt(str,8);
- cout << "\n\ndecrypted: " << str; */
- char filename[85];
- char NewFilename[85];
- string str;
- string a1;
- cout << "enter file to encrypt: ";
- cin >> filename;
- ifstream ifile(filename);
- if(!ifile | !ifile.good())
- {
- cout << "error, invalid file.\n\n";
- main(1,'\0');
- }
- cout << "enter new filename: ";
- cin >> NewFilename;
- ofstream ofile(NewFilename);
- if(!ofile)
- {
- cout << "error, file failed to create.\n\n";
- main(1,'\0');
- }
- int num;
- for(int i = 0; !ifile.eof(); i++)
- {
- getline(ifile,a1);
- str.append(a1);
- }
- //*******************************//
- char abc[str.size() +1];
- for(int i = 0; i <= str.size(); i++)
- abc[i] = str[i];
- //convert 'str' to a char array
- //*******************************//
- encrypt(abc,8);
- cout <<"\n\n\n"<< abc<<"\n\n\n";
- ofile << abc;
- return 0;
- }
- string encrypt(char str[],short key) //encrypt function
- {
- int a = 256-key;
- for(int i = 0; i < sizeof(str); i++)
- {
- if(str[i] < a)
- {
- for(int b = 0; b < key; b++)
- (int)str[i]++;
- }
- }
- return str;
- }
- string decrypt(char str[],short key) //decrypt function
- {
- for(int i = 0; i < sizeof(str); i++)
- {
- int a = 256-key;
- if(str[i] < a)
- {
- for(int b = 0; b < key; b++)
- (int)str[i]--;
- }
- }
- return str;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement