Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <cassert>
- #include <fstream>
- using namespace std;
- const unsigned int R = 15; //random nummer
- void encryption(char& a, unsigned int ri)
- {
- //precondtition
- assert(true);
- //postcondition char a is encryptided
- if (a >= 32)
- a=(a-32+(ri%(128-32)))%(128-32)+32;
- else if (a == 10)
- a='\n';
- else
- a=a;
- }
- void dencryption(char& a, unsigned int ri)
- {
- //precondtition
- assert(true);
- //postcondition char a is encryptided
- if (a >= 32)
- a= (a - (ri % (128 - 32)) + 64) % (128 - 32) + 32;
- else if (a == 10)
- a='\n';
- else
- a=a;
- }
- int main()
- {
- srand(R);
- cout <<"to encryp the text press number" <<endl;
- int number;
- cin >> number;
- ifstream text("test.txt");
- ofstream code("CodeTest.txt");
- if (text)
- {
- while(text)
- {
- char a;
- text.get(a);
- encryption(a,rand());
- cout << a ;
- code.put(a);
- }
- }
- else
- cout<<"Text could not be opend/n" <<endl;
- text.close();
- code.close();
- cout<<"To decode Text press number\n";
- cin>>number;
- ifstream decode("CodeTest.txt");
- ofstream newcode("NewTest.txt");
- if (decode)
- {
- while(decode)
- {
- char a;
- decode.get(a);
- dencryption(a,rand());
- cout << a ;
- newcode.put(a); //put decoded character in the textfile
- }
- }
- else
- cout<<"Text could not be opend" <<endl; //there is no text that can be decoded
- decode.close();
- newcode.close();
- }
Add Comment
Please, Sign In to add comment