Base-64 Encoder/Decoder Sample Codes - Cisco WVC80N User Manual

Wireless-n internet home monitoring camera
Hide thumbs Also See for WVC80N:
Table of Contents

Advertisement

Appendix D

Base-64 Encoder/Decoder Sample Codes

// Standard BASE64 table
// char keyStr[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
// SerComm BASE64 table
char keyStr[] = "ACEGIKMOQSUWYBDFHJLNPRTVXZacegikmoqsuwybdfhjlnprtvxz0246813579=+/";
//--------------------------------------------------------------------
// Description: Encrypt the input data with the base64
// Input:
//
char i_buf[]
// Output:
//
char o_buf[]
// Return:
//
encrypted string length
//--------------------------------------------------------------------
int encode64(char i_buf[], char o_buf[])
{
char chr1 = (char)0;
char chr2 = (char)0;
char chr3 = (char)0;
//These are the 3 bytes to be encoded
int enc1 = 0;
int enc2 = 0;
int enc3 = 0;
int enc4 = 0; //These are the 4 encoded bytes
int i = 0, j = 0; //Position counter
do { //Set up the loop here
Wireless-N Internet Home Monitoring Camera
- input buffer
- output buffer
chr1 = i_buf[i++]; //Grab the first byte
if(i < strlen(i_buf ))
chr2 = i_buf[i++]; //Grab the second byte
if(i < strlen(i_buf ))
chr3 = i_buf[i++]; //Grab the third byte
//Here is the actual base64 encode part.
//There really is only one way to do it.
enc1 = chr1 >> 2;
enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
enc4 = chr3 & 63;
if(chr2 == (char)0) {
enc3 = enc4 = 64;
}
CGI Commands
41

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents