Advertisement
Guest User

crypto

a guest
Jan 31st, 2015
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.61 KB | None | 0 0
  1. // main.cpp
  2. // программа для сокрытия данных
  3.  
  4. #include <iostream>
  5. #include <locale>
  6. #include <cstdlib>
  7. using namespace std;
  8.  
  9. void data_code(); // прототип функции для фишрования
  10. //void data_encode(); // прототип фкнкции для дешифрования
  11.  
  12. class work
  13. {
  14. public:
  15.     void display_menu()
  16.     {
  17.         system("clear");
  18.         cout << endl;
  19.         cout << " Выберите действие : " << endl;
  20.         cout << "   Зашифровать данные: 1" << endl;
  21.         cout << "   Дешифровать данные: 2" << endl;
  22.         cout << "   Выход             : 0" << endl;
  23.         cout << endl;
  24.     }
  25.  
  26.     void wat_do()
  27.     {
  28.         cout << " Что делать: ";
  29.         cin >> process_id;
  30.     }
  31.  
  32.     void triger()
  33.     {
  34.         if( process_id == 0 )
  35.             exit(0);
  36.         else if( process_id == 1 )
  37.         {
  38.             data_code();
  39.         } else if( process_id == 2 )
  40.         {
  41.             ;
  42.            // data_encode();
  43.         } else {
  44.             cout << " Ошибка, не верное значение!!!" << endl;
  45.             cin.get(); cin.get();
  46.         }
  47.     }
  48.  
  49. private:
  50.     int process_id;
  51. };
  52.  
  53. int main()
  54. {
  55.     // inic
  56.     work working;
  57.     setlocale(LC_ALL,"Russian");
  58.  
  59.     // ïîâòîðÿòü
  60.     while(1)
  61.     {
  62.         working.display_menu();
  63.         working.wat_do();
  64.         working.triger();
  65.     }
  66.  
  67.     // end
  68.     return 0;
  69. }
  70.  
  71. void data_code()
  72. {
  73.     // init
  74.     int count_length = 0; // длина кода
  75.     int data_cp; // копия кода
  76.     int interation; // колво операций преобразования
  77.     int data; // код
  78.     int x1, x2, x3, x4; // цифры кода
  79.     int y1, y2; // это
  80.  
  81.     // input interation
  82.     system("clear");
  83.     cout << "\n Введите кол-во интераций : ";
  84.     cin >> interation;
  85.         // if interation
  86.     if( interation < 1 || interation > 80 )
  87.     {
  88.         cout << " Ошибка, не верное значение!!!" << endl;
  89.         cout << "\n Введите кол-во интераций : ";
  90.         cin >> interation;
  91.     }
  92.  
  93.     // input data
  94.     cout << " Введите информацию       : ";
  95.     cin >> data;
  96.         // data length
  97.     data_cp = data;
  98.     while( data_cp != 0 )
  99.     {
  100.         data_cp/=10;
  101.         ++count_length;
  102.     }
  103.         // if data
  104.     while( count_length != 4 )
  105.     {
  106.         // input data code
  107.         cout << " Ошибка, не верная длина!!!" << endl;
  108.         cout << " Введите информацию       : ";
  109.         cin >> data;
  110.  
  111.         // data length
  112.         data_cp = data;
  113.         while( data_cp != 0 )
  114.         {
  115.             data_cp/=10;
  116.             ++count_length;
  117.         }
  118.     }
  119.  
  120.     // lock data
  121.         // get x
  122.     x4 = data % 10;
  123.     x3 = (data / 10) % 10;
  124.     x2 = (data / 100 ) % 10;
  125.     x1 = (data / 1000 ) % 10;
  126.         // get y
  127.     y2 = interation % 10;
  128.     y1 = ( interation / 10 );
  129.  
  130.         // шифрование
  131.             // преобразование
  132.     for( int i = 1; i <= interation; i++ )
  133.     {
  134.         x1 = (x1 * 7) % 10;
  135.         x2 = (x2 * 7) % 10;
  136.         x3 = (x3 * 7) % 10;
  137.         x4 = (x4 * 7) % 10;
  138.     }
  139.             // генерация ключа
  140.     for( int i = 1; i <= 70; i++ )
  141.     {
  142.         y1 = ( y1 * 7 ) % 10;
  143.         y2 = ( y2 * 7 ) % 10;
  144.     }
  145.  
  146.         // Вывод
  147.     cout << "\n Хеш                  : " << x3 << x4 << y2 << y1 << x1 << x2 << endl;
  148.     cout << endl;
  149.     cin.get(); cin.get();
  150. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement