Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- void deblock(char *in, char *base64, FILE * OutputFile, int len)
- {
- if (base64[(int)in[0]] < 64 && base64[(int)in[1]] < 64)
- fprintf(OutputFile, "%c",(base64[(int)in[0]] << 2 | base64[(int)in[1]] >> 4));
- if (base64[(int)in[1]] < 64 && base64[(int)in[2]] < 64)
- fprintf(OutputFile, "%c",(base64[(int)in[1]] << 4 | base64[(int)in[2]] >> 2));
- if (base64[(int)in[2]] < 64 && base64[(int)in[3]] < 64)
- fprintf(OutputFile, "%c",((base64[(int)in[2]] << 6) & 192) | base64[(int)in[3]]);
- }
- void decode (FILE *InputFile, FILE *OutputFile)
- {
- static char base64[] = {
- // ASCII table
- 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
- 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
- 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 62, 64, 64, 64, 64, 63,
- 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 64, 64, 64, 64, 64, 64,
- 64, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
- 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 64, 64, 64, 64, 64,
- 64, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
- 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 64, 64, 64, 64, 64,
- 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
- 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
- 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
- 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
- 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
- 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
- 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
- 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64
- };
- int len = 0;
- int i = 0;
- char buffer[4] = {0};
- while ((len = fread(buffer,sizeof(char),4,InputFile)) >= 1)
- {
- for (i = len; i < 4; i++)
- buffer[i] = 0;
- deblock(buffer,base64,OutputFile,len);
- }
- }
- int check_decode(FILE *file1, FILE *file2)
- {
- int k = 0;
- fseek (file1, 0, SEEK_END);
- if (((ftell(file1)) % 4) == 0)
- {
- fseek(file1,0,SEEK_SET);
- decode(file1,file2);
- }
- else
- {
- k = -1;
- }
- return k;
- }
- int main()
- {
- FILE *file1 = NULL;
- FILE *file2 = NULL;
- if (NULL == (file1 = fopen("INPUT1.txt", "r")))
- {
- printf("Can't open INPUT file!");
- return -1;
- }
- if (NULL == (file2 = fopen("OUTPUT.orig", "wb")))
- {
- printf("Can't create OUTPUT file");
- return -1;
- }
- if ( -1 == check_decode(file1, file2) )
- {
- printf("Eto ne base64");
- return -1;
- }
- fclose(file1);
- fclose(file2);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement