| [ WWW ] in KIDS 글 쓴 이(By): Romance ( 일 권) 날 짜 (Date): 1998년 4월 15일 수요일 오후 04시 22분 03초 제 목(Title): Re: base64 to ASCII 프로그램 있나요? 이상하군요. elm에서 알아서 메뉴가 뜨던데. 어쨌든, base64는 인코딩 방식이기 때문 에 원래 파일이 바이너리면 바이너리로 텍스트면 텍스트로 변환됩니다. 아예 쏘스를 올리니 컴파일 하신후에 실행파일을 뭐 b64decode 등으로 하신후에 b64decode < INPUT.b64 > OUTFILE 과 같이 쓰시면 됩니다. /* public domain */ /* BASE64 on stdin -> converted data on stdout */ #include <stdio.h> unsigned char alphabet[64] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvw xyz0123456789+/"; int main() { static char inalphabet[256], decoder[256]; int i, bits, c, char_count, errors = 0; for (i = (sizeof alphabet) - 1; i >= 0 ; i--) { inalphabet[alphabet[i]] = 1; decoder[alphabet[i]] = i; } char_count = 0; bits = 0; while ((c = getchar()) != EOF) { if (c == '=') break; if (c > 255 || ! inalphabet[c]) continue; bits += decoder[c]; char_count++; if (char_count == 4) { putchar((bits >> 16)); putchar(((bits >> 8) & 0xff)); putchar((bits & 0xff)); bits = 0; char_count = 0; } else { bits <<= 6; } } if (c == EOF) { if (char_count) { fprintf(stderr, "base64 encoding incomplete: at least %d bits trunc ated", ((4 - char_count) * 6)); errors++; } } else { /* c == '=' */ switch (char_count) { case 1: fprintf(stderr, "base64 encoding incomplete: at least 2 bits missin g"); errors++; break; case 2: putchar((bits >> 10)); break; case 3: putchar((bits >> 16)); putchar(((bits >> 8) & 0xff)); break; } } exit(errors ? 1 : 0); } 끝. |