Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- //T W F u
- #define _T ( tmp[0+offset] & 0x3F)
- #define _W ( tmp[1+offset] & 0x3F)
- #define _F ( tmp[2+offset] & 0x3F)
- #define _u ( tmp[3+offset] & 0x3F)
- //M a n
- #define _M ((_T<<2) | (_W>>4))
- #define _a ((_W <<4) | (_F >>2))
- #define _n (((_F&0x03)<<6) | _u)
- int main (){
- int offset=0;//Gestiona por bloques de 4
- int pto=0;//Gestiona por bloques de 3 es el destino
- int menos=0;//elimina = del final
- char *decodificador="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
- char *Codificado="TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlzIHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2YgdGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGludWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRoZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4=";
- /*
- Man is distinguished, not only by his reason, but by this singular passion from other animals,
- which is a lust of the mind, that by a perseverance of delight in the continued and indefatigable
- generation of knowledge, exceeds the short vehemence of any carnal pleasure.
- */
- //char *Codificado="TWFu";//Man
- //char *Codificado="TWFuTWFuTWFuTWFu";//Man
- char *tmp= (char*) calloc (strlen (Codificado)+2,sizeof (char*));
- if (!tmp){printf ("Error calloc \n");return 0;}
- tmp=memcpy (tmp,Codificado,strlen(Codificado)-menos);
- char *claro= (char*) calloc (strlen (Codificado)+4,sizeof (char*));
- if (!claro){printf ("Error calloc \n");return 0;}
- //printf ("%s",tmp);
- //Decodificacion de la base 64
- for (int i=0;i<strlen(Codificado);i++){//Recorre el string
- //printf (" Caracter =%c ",Codificado[i]);
- for(int pos=0;pos < (strlen (decodificador));pos++){//Busca el caracter
- //printf (" Caracter =%c conpara=%c\n",Codificado[i],decodificador[pos]);
- if (tmp[i]==decodificador[pos]){//Lo ha encontrado el caracter
- //printf (" , %d \n",pos);
- tmp[i]=(unsigned char)pos;
- break;
- }
- }
- }
- //Elimina los ==
- if (tmp[strlen(tmp)-1]=='='){tmp[strlen(tmp)-1]='\0';}
- if (tmp[strlen(tmp)-2]=='='){tmp[strlen(tmp)-2]='\0';}
- //Texto limpio original salta de 4 en 4 el destino de 3 en tres
- for (offset=0; offset<(strlen (tmp)); offset+=4 ,pto+=3){
- claro[0+pto]=_M;
- claro[1+pto]=_a;
- claro[2+pto]=_n;
- }
- printf ("%s",claro);
- if (tmp) {free (tmp);}
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement