Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // basic character-int conversions, the underlying idea behind most crypto
- #include <iostream.h>
- #include <stdio.h>
- #include <conio.h>
- #include <fstream.h>
- #define CYPHER 999999
- #define MAXLENGTH 1000
- void encrypt();
- void decrypt();
- void show();
- const char * filename = "msg.txt";
- int main()
- {
- char corn='5';
- while (corn != '4')
- {
- clrscr();
- cout << "\n-----------------------------------" << endl;
- cout << " " << MAXLENGTH << " max chars " << endl;
- cout << "-----------------------------------" << endl;
- cout << "1) Encrypt text " << endl;
- cout << "2) Decrypt text " << endl;
- cout << "3) Show encrypted string" << endl;
- cout << "4) EXIT " << endl;
- cout << "\nselection : ";
- corn = getch();
- cout << corn;
- if (corn == '1')
- encrypt();
- else if (corn == '2')
- decrypt();
- else if (corn == '3')
- show();
- }
- return 0;
- }
- void encrypt()
- {
- char dummy;
- char encrypt[MAXLENGTH];
- for (long x=0;x<=MAXLENGTH;x++)
- encrypt[x] = NULL;
- fflush(stdin);
- cout << "\nEnter text to be encrypted: ";
- gets(encrypt);
- long stat=0;
- cout << endl << "processing your request..";
- ofstream file;
- file.open (filename);
- for (x=0;x<=MAXLENGTH;x++) {
- if ((long)encrypt[x] != NULL)
- file << (long)(encrypt[x] * CYPHER) << " ";
- }
- file << "0";
- file.close();
- cout << "\n\n\nencrypted text stored in " << filename;
- dummy = getch();
- }
- void decrypt()
- {
- long l,m,key;
- ifstream filein;
- filein.open (filename);
- l = filein.tellg();
- filein.seekg (0, ios::end);
- m = filein.tellg();
- // cout << "\n..begining g: " << l << " bytes, ..end g: " << m << " bytes.\n";
- cout << "\nimported file is " << (m-l) << " bytes.\n\n";
- filein.seekg (0, ios::beg);
- long decrypt[MAXLENGTH];
- long count=0;
- for (long i=0;filein.good();i++) {
- filein >> key;
- decrypt[i] = key;
- count++;
- }
- for (i=0;i<count-2;i++)
- cout << (char)(decrypt[i] / CYPHER);
- filein.close();
- cout << "\n\n\nencrypted text stored in " << filename;
- char dummy = getch();
- }
- void show()
- {
- long l,m,key;
- ifstream filein;
- filein.open (filename);
- l = filein.tellg();
- filein.seekg (0, ios::end);
- m = filein.tellg();
- cout << "\nimported file is " << (m-l) << " bytes.\n";
- filein.seekg (0, ios::beg);
- for (long i=0;filein.good();i++) {
- filein >> key;
- cout << key << " " << endl;
- }
- filein.close();
- cout << "\n\n\nencrypted text stored in " << filename;
- char dummy = getch();
Advertisement
Add Comment
Please, Sign In to add comment