mirror of
https://github.com/reactos/reactos.git
synced 2025-08-02 05:35:40 +00:00
Move Arch to irc module.
svn path=/trunk/; revision=13063
This commit is contained in:
parent
85ae2d98f2
commit
568b27baeb
40 changed files with 0 additions and 5 deletions
58
irc/ArchBlackmann/base64.cpp
Normal file
58
irc/ArchBlackmann/base64.cpp
Normal file
|
@ -0,0 +1,58 @@
|
|||
// base64.cpp
|
||||
|
||||
#include "base64.h"
|
||||
|
||||
using std::string;
|
||||
|
||||
static const char* alfabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
|
||||
string base64_encode ( const string& sInput )
|
||||
{
|
||||
unsigned char x=0, topbit=0;
|
||||
int v=0;
|
||||
string sOutput;
|
||||
do
|
||||
{
|
||||
if ( topbit < 6 )
|
||||
{
|
||||
x++;
|
||||
v <<= 8;
|
||||
if ( x <= sInput.length() ) v += sInput[x-1];
|
||||
topbit += 8;
|
||||
}
|
||||
topbit -= 6;
|
||||
if ( x > sInput.length() && !v )
|
||||
break;
|
||||
sOutput += alfabet[(v >> topbit) & 63];
|
||||
v &= (1 << topbit) - 1;
|
||||
} while ( x < sInput.length() || v );
|
||||
int eq = (8 - (sOutput.length() % 4)) % 4;
|
||||
while ( eq-- )
|
||||
sOutput += '=';
|
||||
return sOutput;
|
||||
}
|
||||
|
||||
string base64_decode ( const string& sInput )
|
||||
{
|
||||
unsigned char x=0, topbit=0;
|
||||
int v=0, inlen = sInput.length();
|
||||
string sOutput;
|
||||
while ( inlen && sInput[inlen-1] == '=' )
|
||||
inlen--;
|
||||
do
|
||||
{
|
||||
while ( topbit < 8 )
|
||||
{
|
||||
x++;
|
||||
v <<= 6;
|
||||
if ( x <= inlen ) v += (strchr(alfabet, sInput[x-1]) - alfabet);
|
||||
topbit += 6;
|
||||
}
|
||||
topbit -= 8;
|
||||
if ( x > inlen && !v )
|
||||
break;
|
||||
sOutput += (char)((v >> topbit) & 255);
|
||||
v &= ((1 << topbit) - 1);
|
||||
} while ( x <= inlen || v );
|
||||
return sOutput;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue