[complement-svn] SF.net SVN: complement: [1891] trunk/complement/explore/app/utils
Status: Pre-Alpha
Brought to you by:
complement
From: <com...@us...> - 2008-06-07 17:06:37
|
Revision: 1891 http://complement.svn.sourceforge.net/complement/?rev=1891&view=rev Author: complement Date: 2008-06-07 10:06:27 -0700 (Sat, 07 Jun 2008) Log Message: ----------- base64 encode/decode Added Paths: ----------- trunk/complement/explore/app/utils/base64/ trunk/complement/explore/app/utils/base64/Makefile trunk/complement/explore/app/utils/base64/Makefile.inc trunk/complement/explore/app/utils/base64/base64.cc Property changes on: trunk/complement/explore/app/utils/base64 ___________________________________________________________________ Name: svn:ignore + obj Added: trunk/complement/explore/app/utils/base64/Makefile =================================================================== --- trunk/complement/explore/app/utils/base64/Makefile (rev 0) +++ trunk/complement/explore/app/utils/base64/Makefile 2008-06-07 17:06:27 UTC (rev 1891) @@ -0,0 +1,10 @@ +# -*- Makefile -*- Time-stamp: <07/07/05 09:31:15 ptr> + +SRCROOT := ../../.. + +include Makefile.inc +include ${SRCROOT}/Makefiles/gmake/top.mak + +# INCLUDES += -I${BOOST_DIR} + +LDFLAGS += -Wl,-rpath=${STLPORT_LIB_DIR} Added: trunk/complement/explore/app/utils/base64/Makefile.inc =================================================================== --- trunk/complement/explore/app/utils/base64/Makefile.inc (rev 0) +++ trunk/complement/explore/app/utils/base64/Makefile.inc 2008-06-07 17:06:27 UTC (rev 1891) @@ -0,0 +1,4 @@ +# -*- makefile -*- Time-stamp: <02/07/14 14:03:13 ptr> + +PRGNAME = base64 +SRC_CC = base64.cc Added: trunk/complement/explore/app/utils/base64/base64.cc =================================================================== --- trunk/complement/explore/app/utils/base64/base64.cc (rev 0) +++ trunk/complement/explore/app/utils/base64/base64.cc 2008-06-07 17:06:27 UTC (rev 1891) @@ -0,0 +1,71 @@ + +#include <iostream> + +using namespace std; + +unsigned char a64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; +const char cd64[]="|$$$}rstuvwxyz{$$$$$$$>?@ABCDEFGHIJKLMNOPQRSTUVW$$$$$$XYZ[\\]^_`abcdefghijklmnopq"; + +// void decode( istream ) +// { +// } + +void decodeblock( unsigned char in[4], unsigned char out[3] ) +{ + out[ 0 ] = (unsigned char ) (in[0] << 2 | in[1] >> 4); + out[ 1 ] = (unsigned char ) (in[1] << 4 | in[2] >> 2); + out[ 2 ] = (unsigned char ) (((in[2] << 6) & 0xc0) | in[3]); +} + +#if 1 +void decode( istream& is, ostream& os ) +{ + unsigned char in[4], out[3], v; + int len; + + while( !is.eof() ) { + len = 0; + for( int i = 0; i < 4 && !is.eof(); i++ ) { + v = 0; + while( !is.eof() && v == 0 ) { + is >> v; + v = (unsigned char) ((v < 43 || v > 122) ? 0 : cd64[ v - 43 ]); + if ( v ) { + v = (unsigned char) ((v == '$') ? 0 : v - 61); + } + } + if( !is.eof() ) { + len++; + if ( v ) { + in[ i ] = (unsigned char) (v - 1); + } + } else { + in[i] = 0; + } + } + if ( len ) { + decodeblock( in, out ); + for ( int i = 0; i < len - 1; i++ ) { + os << out[i]; + } + } + } +} +#else +void decode( istream& is, ostream& os ) +{ + unsigned char in[4], out[3], v; + while( !is.eof() ) { + is >> in[0] >> in[1] >> in[2] >> in[3]; + decodeblock( in, out ); + os << out[0] << out[1] << out[2]; + } +} +#endif + +int main() +{ + decode( cin, cout ); + + return 0; +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |