-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
pat
committed
Oct 14, 2015
1 parent
387a622
commit 9a87fa4
Showing
6 changed files
with
59 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#include "Base64.h" | ||
#include <stdio.h> | ||
|
||
#if __GNUC__ >= 4 and __GNUC_MINOR__ >= 3 | ||
#define MOVEBE(x) __builtin_bswap32(x); | ||
#else | ||
#define MOVEBE(x) ((x&0xff000000)>>24)|((x&0xff)<<24)|((x&0xff0000)>>8)|((x&0xff00)<<8) | ||
#endif | ||
|
||
char* Base64::digits = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; | ||
|
||
std::string Base64::encode(const char* data, unsigned int size) | ||
{ | ||
std::string str; | ||
unsigned int tmp; | ||
unsigned int i = 0; | ||
while (i<size) | ||
{ | ||
tmp = MOVEBE(*((unsigned int*)&data[i])); | ||
if (size-i == 1) | ||
{ | ||
str += digits[(tmp>>26)&0x3F]; | ||
str += digits[(tmp>>20)&0x3F]; | ||
str += "=="; | ||
i++; | ||
} | ||
else if (size-i == 2) | ||
{ | ||
str += digits[(tmp>>26)&0x3F]; | ||
str += digits[(tmp>>20)&0x3F]; | ||
str += digits[(tmp>>14)&0x3F]; | ||
str += "="; | ||
i+=2; | ||
} | ||
else | ||
{ | ||
str += digits[(tmp>>26)&0x3F]; | ||
str += digits[(tmp>>20)&0x3F]; | ||
str += digits[(tmp>>14)&0x3F]; | ||
str += digits[(tmp>>8)&0x3F]; | ||
i+=3; | ||
} | ||
} | ||
|
||
return str; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#pragma once | ||
#include <string> | ||
|
||
class Base64 | ||
{ | ||
private: | ||
static char* digits; | ||
public: | ||
static std::string encode(const char* data, unsigned int size); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.