elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Como proteger una cartera - billetera de Bitcoin


  Mostrar Temas
Páginas: [1]
1  Foros Generales / Foro Libre / Wooh, Profesor maltrata niños en: 13 Agosto 2011, 19:21 pm
El Video habla por si solo


Es tan degraciadito el tipo que ni siquiera mira la tarea bien y ya le esta dando golpes, Yo siendo el padre de alguno de esto carajos, bueno aya es legal entrarle granada por detrás a tipos como esto.

Aunque este si me gusto:


Aunque sea mujer pero lo golpe que le doy en el infierno no me aceptan:
2  Programación / Programación C/C++ / [Ayuda] [C++] #include "Base64.hpp" [Solucionado] en: 13 Agosto 2011, 19:05 pm
Saludo, soy nuevo en el foro  :rolleyes:

Estaba buscando algo para cifrar en base64 en c++, encontré esto pero meda problema en #include "base64.hpp" Como soluciono el problema, trato de buscar en google pero nada o por lo menos no  ami, Compilador GCC, IDE CodeBlock.

Código
  1. #include <iostream>
  2. #include <string>
  3. #include <math.h>
  4. #include <cstdio>
  5. #include <cstdlib>
  6.  
  7. using namespace std;
  8.  
  9. class Base64
  10. {
  11. private:
  12.   static string alfabeto;
  13.   static string TextToBinBase(string a, int b);
  14.   static void Reverse(string &a);
  15.   static void Complete(string &a, int b);
  16. public:
  17.   static string Encode(string a);
  18.   static string Decode(string a);
  19.   static string Binary(int a, int b);
  20.   static int BinToInt(string a);
  21.   static string TextToBin(string a, int b);
  22.  
  23. };
  24.  
  25. Base64.cpp
  26. Citar
  27. #include "Base64.hpp"
  28. #include <sstream>
  29.  
  30. using namespace std;
  31.  
  32. string Base64::alfabeto = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  33.  
  34. string Base64::Binary(int a, int b)
  35. {
  36.   string result = "";
  37.   while(a != 0)
  38.   {
  39.      if((a%2) == 0)
  40.         result += '0';
  41.      else
  42.         result += '1';
  43.      a = a/2;
  44.   }
  45.  
  46.   Complete(result, b);
  47.   Reverse(result);
  48.   return result;
  49. }
  50.  
  51. string Base64::Encode(string a)
  52. {
  53.   string binario = TextToBin(a, 8);
  54.   stringstream ret;
  55.   string *buffer;
  56.  
  57.   int padding;
  58.   int alt = binario.length()%6;
  59.   int aux;
  60.  
  61.   if(alt == 0)
  62.   {
  63.      int numcadenas = binario.length() / 6;
  64.      buffer = new string[numcadenas];
  65.      if(buffer != NULL)
  66.      {
  67.         for(int i = 0; i < numcadenas; i++)
  68.         {
  69.            buffer[ i ] = binario.substr(i*6, 6);
  70.            aux = BinToInt(buffer[ i ]);
  71.            ret << alfabeto.at(aux);
  72.         }
  73.  
  74.         delete[] buffer;
  75.      }
  76.   }
  77.   else
  78.   {
  79.      padding = (6 - alt) / 2;
  80.      Complete(binario, binario.length() + (6-alt));
  81.      int numcadenas = binario.length() / 6;
  82.      buffer = new string[numcadenas];
  83.      if(buffer != NULL)
  84.      {
  85.         int i;
  86.         for(i = 0; i < numcadenas; i++)
  87.         {
  88.            buffer[ i ] = binario.substr(i*6, 6);
  89.            aux = BinToInt(buffer[ i ]);
  90.            ret << alfabeto.at(aux);
  91.         }
  92.  
  93.         for(i = 0; i < padding; i++)
  94.            ret<<"=";
  95.  
  96.         delete[] buffer;
  97.      }
  98.   }
  99.  
  100.   return ret.str();
  101. }
  102.  
  103. string Base64::Decode(string a)
  104. {
  105.   string binario;
  106.   string cadena;
  107.   stringstream delpadding;
  108.  
  109.   int i;
  110.  
  111.   for(i = 0; i < a.length(); i++)
  112.   {
  113.      if(a.at(i) != '=')
  114.         delpadding<<a.at(i);
  115.   }
  116.  
  117.   cadena = delpadding.str();
  118.   binario = TextToBinBase(cadena, 6);
  119.  
  120.   stringstream ret;
  121.   string *buffer;
  122.  
  123.   int padding;
  124.   int alt = binario.length()/8;
  125.   int aux;
  126.  
  127.   buffer = new string[alt];
  128.  
  129.   if(buffer != NULL)
  130.   {
  131.      for(i = 0; i < alt; i++)
  132.      {
  133.         buffer[ i ] = binario.substr(i*8, 8);
  134.         aux = BinToInt(buffer[ i ]);
  135.         ret << (char)aux;
  136.      }
  137.      cout<<endl;
  138.      delete[] buffer;
  139.   }
  140.  
  141.   return ret.str();
  142. }
  143.  
  144. string Base64::TextToBin(string a, int b)
  145. {
  146.   stringstream c;
  147.   for(int i = 0; i < a.length(); i++)
  148.   {
  149.      c<<Binary((int)a.at(i), b);
  150.   }
  151.   return c.str();
  152. }
  153.  
  154. string Base64::TextToBinBase(string a, int b)
  155. {
  156.   stringstream c;
  157.   for(int i = 0; i < a.length(); i++)
  158.   {
  159.      int pos = (int)alfabeto.find(a.at(i));
  160.      c<<Binary(pos, b);
  161.   }
  162.   return c.str();
  163. }
  164.  
  165. void Base64::Reverse(string& a)
  166. {
  167.   string aux = "";
  168.   for(int i = 0; i < a.length(); i++)
  169.      aux += a.at(a.length() - i - 1);
  170.   a = aux;
  171. }
  172.  
  173. void Base64::Complete(string &a, int b)
  174. {
  175.   if(a.length() < b)
  176.   {
  177.      int fin = b - a.length();
  178.      a.append(fin, '0');
  179.   }
  180. }
  181.  
  182. int Base64::BinToInt(string a)
  183. {
  184.   int aux = 0;
  185.  
  186.   for(int i = 0; i < a.length(); i++)
  187.   {
  188.      if(a.at(i) == '1')
  189.      {
  190.         float ex = a.length() -i -1;
  191.         aux += (int)pow(2, ex);
  192.      }
  193.   }
  194.  
  195.   return aux;
  196. }
  197.  
  198. Main.cpp
  199. Citar
  200. #include "Base64.hpp"
  201.  
  202. /*
  203. Compilación utilizando g++:
  204. g++ Main.cpp Base64.cpp -o base64
  205.  
  206. Uso:
  207. base64 -flag string
  208. Ej:
  209.    base64 -c hola
  210.  
  211. Flags disponibles:
  212.  
  213. -c : cifra
  214. -d : descifra
  215.  
  216. Se pueden cifrar cadenas más grandes a una sola palabra si se coloca todo entre comillas dobles
  217. Ej:
  218.    base64 -c "cifrando textos con espacios"
  219. */
  220.  
  221. using namespace std;
  222.  
  223. void usage()
  224. {
  225.   cout<<"Usage: "<<endl;
  226.   cout<<"base64 -c string || Crypt a string to a Base64 string"<<endl;
  227.   cout<<"base64 -d string || Decrypt a Base64 string"<<endl;
  228. }
  229.  
  230. int main(int argv, char** args)
  231. {
  232.   if(argv != 3)
  233.   {
  234.      usage();
  235.   }
  236.   else
  237.   {
  238.      string op, str;
  239.      op = args[1];
  240.      str = args[2];
  241.  
  242.      if(op == "-d")
  243.      {
  244.         cout<<Base64::Decode(str)<<endl;
  245.      }
  246.      if(op == "-c")
  247.      {
  248.         cout<<Base64::Encode(str)<<endl;
  249.      }
  250.      if( (op != "-c") && (op != "-d"))
  251.      {
  252.         usage();
  253.      }
  254.   }
  255.   return 0;
  256. }
  257.  
Páginas: [1]
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines