Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- char char_xor( char A, char B );
- string xor_string( string sekret, string losowy )
- {
- string result;
- int dlugosc = sekret.length();
- for(int i = 0; i < dlugosc; ++i)
- {
- char c = char_xor( sekret[i], losowy[i] );
- result += c;
- }
- return result;
- }
- string losowy_ciag( string sekret )
- {
- string result;
- int dlugosc = sekret.length();
- for(int i = 0; i < dlugosc; ++i)
- {
- int los = rand() % 2;
- if(los)
- {
- result += '1';
- }
- else
- {
- result += '0';
- }
- }
- return result;
- }
- char char_xor( char A, char B )
- {
- if(A == '0' and B == '0') return '0';
- if(A == '1' and B == '1') return '0';
- if(A == '1' and B == '0') return '1';
- if(A == '0' and B == '1') return '1';
- }
- int main()
- {
- srand(time(NULL));
- string sekret;
- cout << "podaj cyfry sekretu: ";
- cin >> sekret;
- string losowy = losowy_ciag( sekret );
- cout << "losowy ciag: " << losowy << endl;
- string xor_str = xor_string(sekret, losowy);
- cout << "zxorowany string: " << xor_str << endl;
- string input;
- cout << "czy chcesz odszyfrować sekret? (y/n)";
- cin >> input;
- if(input == "y")
- {
- string odzyskany_sekret = xor_string( xor_str, losowy );
- cout << "odzyskany sekret: " << odzyskany_sekret << endl;
- }
- system("pause");
- return 0;
- }
Add Comment
Please, Sign In to add comment