Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string.h>
- using namespace std;
- int main()
- {
- fstream filino ;
- filino.open("file.txt") ;
- if(!filino)
- {
- cout << "File inesistente" ;
- return 0 ;
- }
- char parola_cifrata[10] ;
- filino>> parola_cifrata ;
- cout << parola_cifrata ;
- char alfabeto[21] = {'a','b','c','d','e','f','g','h','i','l','m','n','o','p','q','r','s','t','u','v','z'};
- char alfabeto_modificato[21] ;
- //int prec = 10 ;
- int last_pos = 0 ;
- int dimensione = strlen(parola_cifrata) ;
- int array[dimensione] ;
- for (int i = 0 ; i < dimensione ; i++)
- {
- for(int j = 0 ; j<21; j++)
- {
- if (parola_cifrata[i] == alfabeto[j])
- {
- array[i] = j ;
- }
- }
- }
- for(int prec = 0; prec < 21 ; prec ++)
- {
- cout << "Alfabeto con shift:" << prec << " :" ;
- for (int i = 0 ; i < 21 ; i ++)
- {
- alfabeto_modificato[i] = alfabeto[i+prec] ;
- last_pos = i ;
- if ((i+prec)>20)
- {
- // cout << "Valore fermo: " << i << endl ;
- goto start;
- }
- //cout << "valore i: " << i << endl ;
- }
- start:
- for (int j = 0 ; j < prec ; j++)
- {
- for (int i = last_pos ; i < 21 ; i++)
- {
- alfabeto_modificato[i] = alfabeto[j] ;
- j++ ;
- }
- }
- for (int i = 0 ; i < 21 ; i ++)
- {
- cout << alfabeto_modificato[i] ;
- }
- cout << "parola con alfabeto modificato: " ;
- for(int i = 0 ; i < dimensione ; i++)
- {
- cout << alfabeto_modificato[array[i]];
- }
- cout << endl << endl ;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment