Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <windows.h>
- using namespace std;
- void line_out(bool * line, int len){
- for (int i =0; i < len; i++){
- cout << line[i] << (((i+1) % 8 == 0) ? " " : "");
- }
- }
- bool * scramble(bool * a_line, int len, bool descr){
- bool *line = new bool[len];
- bool *c_line = new bool[len];
- if (descr == 1)
- line = a_line;
- for (int i = 0; i < len; i++){
- if( i < 5 )
- (descr == 1 ? c_line[i] : line[i] ) = a_line[i];
- else if ( i < 9 )
- (descr == 1 ? c_line[i] : line[i] ) = a_line[i] ^ line[i - 5];
- else if ( i < 11 )
- (descr == 1 ? c_line[i] : line[i] ) = a_line[i] ^ line[i - 5] ^ line[i - 9];
- else
- (descr == 1 ? c_line[i] : line[i] ) = a_line[i] ^ line[i - 5] ^ line[i - 9] ^ line[i - 11];
- }
- return ((descr == 1 ? c_line : line ));
- }
- void compare (bool * a_line, bool * b_line, int len){
- int ne = 0;
- for (int i =0; i < len; i++){
- ne += (a_line[i] != b_line[i])? 1 : 0;
- }
- cout << ((ne == 0)? "equal sequences" : "differ. sequences");
- }
- int main()
- {
- string line;
- cout << "Enter your sequence!" << endl;
- getline(cin, line);
- bool *a_line = new bool[line.length()];
- bool *b_line = new bool[line.length()];
- bool *c_line = new bool[line.length()];
- for (int i = 0; i < line.length(); i++) {
- if (line[i] == ' ')
- line.erase(i, 1);
- }
- for (int i = 0; i < line.length(); i++) {
- a_line[i] = (int(line[i]) == 48) ? 0 : 1;
- }
- system("cls");
- cout << "Original sequence: ";
- line_out(a_line, line.length());
- cout << endl;
- b_line = scramble(a_line, line.length(),0);
- cout << "Scrambled sequence: ";
- line_out(b_line, line.length());
- cout << endl;
- c_line = scramble(b_line, line.length(),1);
- cout << "Descrambled sequence: ";
- line_out(c_line, line.length());
- cout << endl;
- cout << "After scrambling and descrambling we got - ";
- compare(a_line, c_line, line.length());
- delete a_line;
- delete b_line;
- delete c_line;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement