Ver Mensaje Individual
  #3 (permalink)  
Antiguo 27/10/2015, 06:15
aguml
 
Fecha de Ingreso: febrero-2015
Mensajes: 404
Antigüedad: 9 años, 2 meses
Puntos: 3
Respuesta: ¿Buffer de entrada en modo binario?

No veo la manera de hacerlo. He estado intentando usar unsigned char*, wstring, freopen para abrir el buffer de entrada en modo binario y luego leer con read en binario,... y nada.
El codigo lo tengo ahora mismo asi:
Parte 1:
Código C++:
Ver original
  1. //---------------------------------------------------------------------------
  2.  
  3. #include <iostream>
  4. #include <cstdlib>
  5. #include <fstream>
  6.  
  7. string CesarEncriptText(string entrada, int desplazamiento);
  8. string CesarDecriptText(string entrada, int desplazamiento);
  9. int CesarEncriptFile(char *nameFileIn, int desplazamiento, char *nameFileOut);
  10. int CesarDecriptFile(char *nameFileIn, int desplazamiento, char *nameFileOut);
  11. void OpcionEncriptFile();
  12. void OpcionDecriptFile();
  13.  
  14. string Letras="ABCDEFGHIJKLMNÑOPQRSTUVWXYZabcdefghijklmnñopqrstuvwxyz1234567890ÁÉÍÓÚáéíóúÜü \".,:;-+*/=\\_<>¡!¿?|@#$%&()[]{}\'^ºª";
  15. //---------------------------------------------------------------------------
  16.  
  17. int main(int argc, char* argv[])
  18. {
  19.    char aux[1024];
  20.    string desencriptado;
  21.    string encriptado;
  22.    int op,salir=0,volver=0,rotacion;
  23.  
  24.    do{
  25.       cout << "Cifrado/Descifrado Cesar" << endl;
  26.       cout << "------------------------" << endl;
  27.       cout << "1.Texto" << endl;
  28.       cout << "2.Archivo" << endl;
  29.       cout << "3.Salir" << endl;
  30.       cout << "Elige una opcion: ";
  31.       cin >> op;
  32.       cin.clear();
  33.  
  34.       // Ignore to the end of file
  35.       //cin.ignore(std::numeric_limits<std::streamsize>::max());
  36.  
  37.       // Ignore to the end of line
  38.       cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
  39.  
  40.       switch(op){
  41.          case 1:
  42.             do{
  43.                system("CLS");
  44.                cout << "Cifrado/Descifrado de texto con cifrado Cesar" << endl;
  45.                cout << "---------------------------------------------" << endl;
  46.                cout << "1.Encriptar texto" << endl;
  47.                cout << "2.Desencriptar texto" << endl;
  48.                cout << "3.Volver" << endl;
  49.                cout << "Elige una opcion: ";
  50.                cin >> op;
  51.                cin.clear();
  52.  
  53.                // Ignore to the end of line
  54.                cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
  55.  
  56.                switch(op){
  57.                   case 1:
  58.                      cout << "Introduce el texto a encriptar: ";
  59.                      cin.getline(aux,1023,'\n');
  60.                      desencriptado=aux;
  61.                      cout << "Introduce el desplazamiento: ";
  62.                      cin >> rotacion;
  63.  
  64.                      // Ignore to the end of line
  65.                      cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
  66.  
  67.                      if((encriptado=CesarEncriptText(desencriptado,rotacion)) != ""){
  68.                         cout << "Encriptado finalizado satisfactoriamente" << endl;
  69.                         cout << "Encriptado queda: " << encriptado << endl;
  70.                      }else{
  71.                         cout << "Caracteres no validos en el texto a encriptar" << endl;
  72.                      }
  73.                      cin.get();
  74.                      break;
  75.                   case 2:
  76.                      cout << "Introduce el texto a desencriptar: ";
  77.                      cin.getline(aux,1023,'\n');
  78.                      encriptado=aux;
  79.                      cout << "Introduce el desplazamiento: ";
  80.                      cin >> rotacion;
  81.  
  82.                      // Ignore to the end of line
  83.                      cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
  84.  
  85.                      if((desencriptado=CesarDecriptText(encriptado,rotacion)) != ""){
  86.                         cout << "Encriptado finalizado satisfactoriamente" << endl;
  87.                         cout << "Desencriptado queda: " << desencriptado << endl;
  88.                      }else{
  89.                         cout << "Caracteres no validos en el texto a desencriptar" << endl;
  90.                      }
  91.                      cin.get();
  92.                      break;
  93.                   case 3:
  94.                      volver=1;
  95.                      break;
  96.                   default:
  97.                      cout << "Opcion no valida. Pulsa intro y vuelve a intentarlo" << endl;
  98.                      cin.get();
  99.                }
  100.             }while(volver==0);
  101.             cin.get();
  102.             system("CLS");
  103.             break;
  104.  
  105.          case 2:
  106.             do{
  107.                system("CLS");
  108.                cout << "Cifrado/Descifrado de archivo con cifrado Cesar" << endl;
  109.                cout << "-----------------------------------------------" << endl;
  110.                cout << "1.Encriptar archivo" << endl;
  111.                cout << "2.Desencriptar archivo" << endl;
  112.                cout << "3.Volver" << endl;
  113.                cout << "Elige una opcion: ";
  114.                cin >> op;
  115.                cin.clear();
  116.  
  117.                // Ignore to the end of line
  118.                cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
  119.  
  120.                switch(op){
  121.                   case 1:
  122.                      OpcionEncriptFile();
  123.                      cin.get();
  124.                      break;
  125.                   case 2:
  126.                      OpcionDecriptFile();
  127.                      cin.get();
  128.                      break;
  129.                   case 3:
  130.                      volver=1;
  131.                      break;
  132.                   default:
  133.                      cout << "Opcion no valida. Pulsa intro y vuelve a intentarlo" << endl;
  134.                      cin.get();
  135.                }
  136.             }while(volver==0);
  137.             system("CLS");
  138.             break;
  139.  
  140.          case 3:
  141.             salir=1;
  142.             break;
  143.  
  144.          default:
  145.             cout << "Opcion no valida" << endl;
  146.       }
  147.    }while(salir == 0);
  148.    return 0;
  149. }