資源簡介
使用Base64編解碼圖片的小例子,希望可以對您的學習有幫助。

代碼片段和文件信息
/*
??Copyright?(c)?2005-2009?by?Jakob?Schroeter?
??This?file?is?part?of?the?gloox?library.?http://camaya.net/gloox
??This?software?is?distributed?under?a?license.?The?full?license
??agreement?can?be?found?in?the?file?LICENSE?in?this?distribution.
??This?software?may?not?be?copied?modified?sold?or?distributed
??other?than?expressed?in?the?named?license?agreement.
??This?software?is?distributed?without?any?warranty.
*/
#include?“stdafx.h“
#include?“base64.h“
namespace?gloox
{
??namespace?base64
??{
????static?const?std::string?alphabet64(?“ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/“?);
????static?const?char?pad?=?‘=‘;
????static?const?char?np??=?(char)std::string::npos;
????static?char?table64vals[]?=
????{
??????62?np?np?np?63?52?53?54?55?56?57?58?59?60?61?np?np?np?np?np
??????np?np??0??1??2??3??4??5??6??7??8??9?10?11?12?13?14?15?16?17
??????18?19?20?21?22?23?24?25?np?np?np?np?np?np?26?27?28?29?30?31
??????32?33?34?35?36?37?38?39?40?41?42?43?44?45?46?47?48?49?50?51
????};
????inline?char?table64(?unsigned?char?c?)
????{
??????return?(?c?43?||?c?>?122?)???np?:?table64vals[c-43];
????}
????const?std::string?encode64(?const?std::string&?input?)
????{
??????std::string?encoded;
??????char?c;
??????const?std::string::size_type?length?=?input.length();
??????encoded.reserve(?length?*?2?);
??????for(?std::string::size_type?i?=?0;?i???????{
????????c?=?static_cast(?(?input[i]?>>?2?)?&?0x3f?);
????????encoded?+=?alphabet64[c];
????????c?=?static_cast(?(?input[i]?<4?)?&?0x3f?);
????????if(?++i???????????c?=?static_cast(?c?|?static_cast(?(?input[i]?>>?4?)?&?0x0f?)?);
????????encoded?+=?alphabet64[c];
????????if(?i?????????{
??????????c?=?static_cast(?(?input[i]?<2?)?&?0x3c?);
??????????if(?++i?????????????c?=?static_cast(?c?|?static_cast(?(?input[i]?>>?6?)?&?0x03?)?);
??????????encoded?+=?alphabet64[c];
????????}
????????else
????????{
??????????++i;
??????????encoded?+=?pad;
????????}
????????if(?i?????????{
??????????c?=?static_cast(?input[i]?&?0x3f?);
??????????encoded?+=?alphabet64[c];
????????}
????????else
????????{
??????????encoded?+=?pad;
????????}
??????}
??????return?encoded;
????}
????const?std::string?decode64(?const?std::string&?input?)
????{
??????char?c?d;
??????const?std::string::size_type?length?=?input.length();
??????std::string?decoded;
??????decoded.reserve(?length?);
??????for(?std::string::size_type?i?=?0;?i???????{
????????c?=?table64(input[i]);
????????++i;
????????d?=?table64(input[i]);
????????c?=?static_cast(?(?c?<2?)?|?(?(?d?>>?4?)?&?0x3?)?);
????????decoded?+=?c;
????????if(?++i?????????{
??????????c?=?input[i];
??????????if(?pad?==?c?)
????????????break;
??????????c?=?table64(input[i]);
??????????d?=?static_cast(?(?(?d?<4?)?&?0xf0?)?|?(?(?
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????3335??2014-03-27?12:10??ba
?????文件???????1194??2014-03-26?11:27??ba
?????文件???????1753??2014-03-27?13:28??ba
?????文件???????4699??2014-03-27?13:27??ba
?????文件???????1413??2014-03-28?07:32??ba
?????文件???????1417??2014-03-27?13:29??ba
?????文件???????1441??2009-10-13?00:24??ba
?????文件???????1330??2014-03-27?12:09??ba
?????文件??????12040??2014-03-25?08:52??ba
?????文件??????12040??2014-03-27?13:28??ba
?????文件????????298??2014-03-27?12:09??ba
?????文件????????516??2014-03-27?12:09??ba
?????文件????????898??2014-03-27?12:09??ba
?????目錄??????????0??2014-03-28?07:32??ba
?????目錄??????????0??2014-03-28?07:33??ba
-----------?---------??----------?-----??----
????????????????42374????????????????????15
評論
共有 條評論