#include <stdlib.h> #include <stdio.h> #include <ctype.h> int decode_b64char( int ch ) { int sextet; if( ('A' <= ch) && (ch <= 'Z') ) sextet = ch - 'A'; else if( ('a' <= ch) && (ch <= 'z') ) sextet = (ch - 'a') + 26; else if( ('0' <= ch) && (ch <= '9') ) sextet = (ch - '0') + 52; else if( ch == '+' ) sextet = 62; else if( ch == '/' ) sextet = 63; else { fprintf( stderr, (isprint(ch) ? "Illegal base64 character '%c'\n" : "Illegal base64 character 0x%02x\n"), ch ); exit( EXIT_FAILURE ); } return( sextet ); } main( int argc, char *argv[] ) { FILE *fin; FILE *fout; int flushing = 0; int temp = 0; int bits = 0; int ch; if( argc < 2 ) { fprintf( stderr, "Usage: b64decode <infile> [outfile]\n" ); exit( EXIT_SUCCESS ); } fin = fopen( argv[1], "r" ); if( fin == NULL ) { perror( "openin" ); exit( EXIT_FAILURE ); } if( argc < 3 ) fout = stdout; else { fout = fopen( argv[2], "wb" ); if( fout == NULL ) { perror( "openout" ); fclose( fin ); exit( EXIT_FAILURE ); } } while( (ch = fgetc( fin )) != EOF ) { if( !isspace(ch) ) { if( flushing ) { if( ch != '=' ) { fprintf( stderr, "Illegal character in EOF padding\n" ); exit( EXIT_FAILURE ); } } else { if( ch == '=' ) flushing = 1; else { temp <<= 6; temp |= decode_b64char( ch ); bits += 6; if( bits >= 8 ) { bits -= 8; fputc( (0xff & (temp >> bits)), fout ); } } } } } fclose( fout ); fclose( fin ); }
file: /Techref/method/codec/B64DEC.txt, 1KB, , updated: 1999/12/21 11:55, local time: 2024/8/21 20:20,
3.131.38.22:LOG IN
|
©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions? <A HREF="http://piclist.com/tecHREF/method/codec/B64DEC.txt"> method codec B64DEC</A> |
Did you find what you needed? |
![]() o List host: MIT, Site host massmind.org, Top posters @none found - Page Editors: James Newton, David Cary, and YOU! * Roman Black of Black Robotics donates from sales of Linistep stepper controller kits. * Ashley Roll of Digital Nemesis donates from sales of RCL-1 RS232 to TTL converters. * Monthly Subscribers: Gregg Rew. on-going support is MOST appreciated! * Contributors: Richard Seriani, Sr. |
Welcome to piclist.com! |
.