kozubovskyy

Cifrario romano

Nov 28th, 2023 (edited)
1,021
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.88 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string.h>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.  
  10.     fstream filino ;
  11.     filino.open("file.txt") ;
  12.     if(!filino)
  13.     {
  14.         cout << "File inesistente" ;
  15.         return 0 ;
  16.     }
  17.     char parola_cifrata[10] ;
  18.  
  19.     filino>> parola_cifrata ;
  20.     cout << parola_cifrata ;
  21.  
  22.  
  23.     char alfabeto[21] = {'a','b','c','d','e','f','g','h','i','l','m','n','o','p','q','r','s','t','u','v','z'};
  24.     char alfabeto_modificato[21] ;
  25.     //int prec = 10 ;
  26.     int last_pos = 0 ;
  27.  
  28.     int dimensione = strlen(parola_cifrata) ;
  29.  
  30.     int array[dimensione] ;
  31.     for (int i = 0 ; i < dimensione ; i++)
  32.     {
  33.         for(int j = 0 ; j<21; j++)
  34.         {
  35.             if (parola_cifrata[i] == alfabeto[j])
  36.                 {
  37.                     array[i] = j ;
  38.                 }
  39.         }
  40.     }
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.     for(int prec = 0; prec < 21 ; prec ++)
  48.     {
  49.         cout << "Alfabeto con shift:" << prec << " :" ;
  50.         for (int i = 0 ; i < 21 ; i ++)
  51.         {
  52.             alfabeto_modificato[i] =  alfabeto[i+prec] ;
  53.             last_pos = i ;
  54.             if ((i+prec)>20)
  55.             {
  56.                // cout << "Valore fermo: " << i << endl ;
  57.                 goto start;
  58.             }
  59.         //cout << "valore i: " << i << endl ;
  60.  
  61.         }
  62.  
  63.         start:
  64.         for (int j = 0 ; j < prec ; j++)
  65.         {
  66.             for (int i = last_pos ; i < 21 ; i++)
  67.             {
  68.                 alfabeto_modificato[i] = alfabeto[j] ;
  69.                 j++ ;
  70.             }
  71.  
  72.  
  73.         }
  74.         for (int i = 0 ; i < 21 ; i ++)
  75.         {
  76.             cout << alfabeto_modificato[i] ;
  77.         }
  78.         cout << "parola con alfabeto modificato: " ;
  79.         for(int i = 0 ; i < dimensione ; i++)
  80.         {
  81.             cout << alfabeto_modificato[array[i]];
  82.         }
  83.         cout << endl << endl ;
  84.     }
  85.  
  86.  
  87.  
  88.  
  89.     return 0;
  90. }
  91.  
Advertisement
Add Comment
Please, Sign In to add comment