Created
July 28, 2012 14:02
-
-
Save ochoto/3193528 to your computer and use it in GitHub Desktop.
Expand 2 bit raw to byte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
void expand(const char c, char b[4]) { | |
b[0] = c & 3; | |
b[1] = (c >> 2) & 3; | |
b[2] = (c >> 4) & 3; | |
b[3] = (c >> 6) & 3; | |
} | |
int main(int argc,char* argv[]) { | |
FILE* fp = fopen("password.raw","rb"); | |
if(!fp) { | |
printf("Error al abrir el fichero\n"); | |
exit(-1); | |
} | |
FILE* of = fopen("password_byte.raw","wb"); | |
if(!of) { | |
printf("Error al abrir el fichero de salida\n"); | |
exit(-2); | |
} | |
char c = 0; | |
char buff[4]; | |
while((c=fgetc(fp))!=FEOF) { | |
expand(c,buff) | |
fputc(of,buff[0]); | |
fputc(of,buff[1]); | |
fputc(of,buff[2]); | |
fputc(of,buff[3]); | |
} | |
fclose(fp); | |
fclose(of); | |
exit(0); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment