Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <conio.h>
- #include <ctime>
- #include <cstdlib>
- #include <string.h>
- using namespace std;
- int main(){
- string alfabeto = "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890";
- string parola = "";
- string flora[] = {"albero","rosa","fiori","petalo","pistillo","tulipano","cactus","giglio","erba","margherita"};
- string chiave = "";
- string finale = "";
- char ch;
- cout << "Inserire il testo: " ;
- cin >> parola;
- /*ch = _getch();
- while(ch != 13){
- parola.push_back(ch);
- cout << '*';
- ch = _getch();
- }
- */
- srand(time(NULL));
- int caso = rand() % sizeof(flora)/sizeof(string);
- chiave = flora[caso];
- cout << chiave;
- for (int i = 0;i!=parola.size();i++){
- char lettera;
- bool carattereSpeciale = true;
- for(int a = 0; a != alfabeto.length();a++){
- if (parola[i] == alfabeto[a]){
- carattereSpeciale = false;
- break;
- }
- }
- if (carattereSpeciale) {
- lettera = parola[i];
- } else
- {
- int posParola;
- int posChiave;
- for(int a = 0; a != alfabeto.length();a++){
- if (alfabeto[a] == parola[i]){
- posParola = a;
- break;
- }
- }
- for(int a = 0; a != alfabeto.length();a++){
- if (alfabeto[a] == chiave[i]){
- posChiave = a;
- break;
- }
- }
- int posAlfa = posChiave + posParola;
- lettera = alfabeto[posAlfa-((posAlfa/alfabeto.length())*alfabeto.length())];
- }
- finale.push_back(lettera);
- }
- cout << endl << " Codice criptato: "<<finale;
- }
- //BACK
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement