Neko250

Cryptex

Oct 16th, 2012
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.46 KB | None | 0 0
  1. /*
  2.        ==========================================
  3.        ||                                      ||
  4.        ||          Programa creado por:        ||
  5.        ||      Carlos Aguilar de la Morena     ||
  6.        ||          Pablo Sabín Cazorla         ||
  7.        ||           El  10 / 10 / 2012         ||
  8.        ||                                      ||
  9.        ==========================================
  10. */
  11.  
  12. #include <iostream>
  13. #include <stdlib.h>
  14. #include <string.h>
  15. using namespace std;
  16.  
  17. int main()
  18. {
  19.     int salt(0), intentos(3), random(1), i(0);
  20.     char opcion('E'), frase[150];
  21.     string pass("password");
  22.  
  23.     cout << "\n\tBienvenido\n\n";
  24.     cout << "Introduce el password para comenzar: ";
  25.     cin >> pass;
  26.  
  27.     while((pass != ("mushroom")) && (pass != ("1123581321")))
  28.     {
  29.         intentos -= 1;
  30.         if(intentos == 0)
  31.         {
  32.             cout << endl << "Usuario no identificado\n";
  33.             system("pause");
  34.             return 0;
  35.         }
  36.         cout << endl << "Password Incorrecto. Acceso Denegado\n"
  37.              << "Intentelo de nuevo, le quedan " << intentos << " intentos: ";
  38.         cin >> pass;
  39.     }
  40.  
  41.     if(pass == "1123581321")
  42.     {
  43.         cout << endl << "Password Correcto. Acceso Concedido\n"
  44.              << "\n\tBienvenido, Carlos, a Cryptex\n\n";
  45.     }
  46.     else
  47.     {
  48.         cout << endl << "Password Correcto. Acceso Concedido\n"
  49.              << "\n\tBienvenido, Pablo, a Cryptex\n\n";
  50.     }
  51.  
  52.     cout << "Que modo desea usar? ==> ";
  53.     cin >> opcion;
  54.    
  55.     while((opcion != 'E') && (opcion != 'D'))
  56.     {
  57.         cout << "Las opciones disponibles son 'E' (Encriptar) y 'D' (Desencriptar)\n"
  58.              << "Intentelo de nuevo ==> ";
  59.         cin >> opcion;
  60.     }
  61.  
  62.     if(opcion == 'E')
  63.     {
  64.         cout << "Introduzca la Sal: ";
  65.         cin >> salt;
  66.         cout << "\nIntroduzca los caracteres:\n\n";
  67.  
  68.         while(random > 0)
  69.         {
  70.             cin >> frase;
  71.             for(; i < strlen(frase); i++)
  72.             {
  73.                 if((int(frase[i]) + salt) > 126)
  74.                 {
  75.                     frase[i] = ((int(frase[i]) + salt) - 126 + 32);
  76.                 }
  77.                 else
  78.                 {
  79.                     frase[i] = (int(frase[i]) + salt);
  80.                 }
  81.             }
  82.             cout << "\t" << frase;
  83.             i = 0;
  84.             cout << endl << endl;
  85.         }
  86.     }
  87.  
  88.     if(opcion == 'D')
  89.     {
  90.         cout << "Introduzca la Sal: ";
  91.         cin >> salt;
  92.         cout << "\nIntroduzca los caracteres:\n\n";
  93.  
  94.         while(random > 0)
  95.         {
  96.             cin >> frase;
  97.             for(; i < strlen(frase); i++)
  98.             {
  99.                 if((int(frase[i]) - salt) < 33)
  100.                 {
  101.                     frase[i] = ((int(frase[i]) - salt) + 126 - 32);
  102.                 }
  103.                 else
  104.                 {
  105.                     frase[i] = (int(frase[i]) - salt);
  106.                 }
  107.             }
  108.             cout << "\t" << frase;
  109.             i = 0;
  110.             cout << endl << endl;
  111.         }
  112.     }
  113.  
  114.     return 0;
  115. }
Advertisement
Add Comment
Please, Sign In to add comment