Advertisement
Guest User

CRIPTA

a guest
Nov 10th, 2017
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.38 KB | None | 0 0
  1.         #include <iostream>
  2.         #include <string>
  3.         #include <conio.h>
  4.         #include <ctime>
  5.         #include <cstdlib>
  6.         #include <string.h>
  7.  
  8.         using namespace std;
  9.         int main(){
  10.             string alfabeto = "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890";
  11.             string parola = "";
  12.             string flora[] =  {"albero","rosa","fiori","petalo","pistillo","tulipano","cactus","giglio","erba","margherita"};
  13.             string chiave = "";
  14.             string finale = "";
  15.             char ch;
  16.            cout << "Inserire il testo: " ;
  17.            cin >> parola;
  18.            /*ch = _getch();
  19.            while(ch != 13){
  20.               parola.push_back(ch);
  21.               cout << '*';
  22.               ch = _getch();
  23.            }
  24. */
  25.             srand(time(NULL));
  26.             int caso = rand() % sizeof(flora)/sizeof(string);
  27.             chiave = flora[caso];
  28.             cout << chiave;
  29.             for (int i = 0;i!=parola.size();i++){
  30.                 char lettera;
  31.                 bool carattereSpeciale = true;
  32.                 for(int a = 0; a != alfabeto.length();a++){
  33.                     if (parola[i] == alfabeto[a]){
  34.                         carattereSpeciale = false;
  35.                         break;
  36.                     }
  37.                 }
  38.                 if (carattereSpeciale) {
  39.                     lettera = parola[i];
  40.                 } else
  41.                 {
  42.                     int posParola;
  43.                         int posChiave;
  44.                         for(int a = 0; a != alfabeto.length();a++){
  45.                             if (alfabeto[a] == parola[i]){
  46.                                 posParola = a;
  47.                                 break;
  48.                             }
  49.                         }
  50.                         for(int a = 0; a != alfabeto.length();a++){
  51.                             if (alfabeto[a] == chiave[i]){
  52.                                 posChiave = a;
  53.                                 break;
  54.                             }
  55.                         }
  56.                         int posAlfa = posChiave + posParola;
  57.                         lettera = alfabeto[posAlfa-((posAlfa/alfabeto.length())*alfabeto.length())];
  58.  
  59.                 }
  60.  
  61.  
  62.  
  63.  
  64.             finale.push_back(lettera);
  65.  
  66.             }
  67.             cout << endl << "  Codice criptato: "<<finale;
  68.            }
  69.  
  70.  
  71.  
  72.         //BACK
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement