please dont rip this site

Method Codec BASE64-ENCODE.TXT

/ * public domain */

/*
 * arbitrary data on stdin -> BASE64 data on stdout
 *
 * UNIX's newline convention is used, i.e. one ASCII control-j (10 decimal).
 */

#include <stdio.h>

unsigned char alphabet[64] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";

int
main()
{
    int cols, bits, c, char_count;

    char_count = 0;
    bits = 0;
    cols = 0;
    while ((c = getchar()) != EOF) {
	if (c > 255) {
	    fprintf(stderr, "encountered char > 255 (decimal %d)", c);
	    exit(1);
	}
	bits += c;
	char_count++;
	if (char_count == 3) {
	    putchar(alphabet[bits >> 18]);
	    putchar(alphabet[(bits >> 12) & 0x3f]);
	    putchar(alphabet[(bits >> 6) & 0x3f]);
	    putchar(alphabet[bits & 0x3f]);
	    cols += 4;
	    if (cols == 72) {
		putchar('\n');
		cols = 0;
	    }
	    bits = 0;
	    char_count = 0;
	} else {
	    bits <<= 8;
	}
    }
    if (char_count != 0) {
	bits <<= 16 - (8 * char_count);
	putchar(alphabet[bits >> 18]);
	putchar(alphabet[(bits >> 12) & 0x3f]);
	if (char_count == 1) {
	    putchar('=');
	    putchar('=');
	} else {
	    putchar(alphabet[(bits >> 6) & 0x3f]);
	    putchar('=');
	}
	if (cols > 0)
	  putchar('\n');
    }

    exit(0);
}


file: /Techref/method/codec/base64-encode.txt, 1KB, , updated: 1999/12/21 11:55, local time: 2024/3/28 18:44,
TOP NEW HELP FIND: 
44.200.169.91: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?
Please DO link to this page! Digg it! / MAKE!

<A HREF="http://massmind.org/techref/method/codec/base64-encode.txt"> method codec base64-encode</A>

Did you find what you needed?

 

Welcome to massmind.org!

 

Welcome to massmind.org!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .