|
Location: Desktop development - C/C++ License: The Intelliproject Open License (IPOL) Encoding and decoding base64 with C++Posted by Silviu CarageaDescribes how Base64 encoding Works |
Skill: IntermediatePosted: 21/11/2008Views: 775Rating: 4.00 /5Popularity: 0.00 |
| Sign Up to vote for this article |
The Base 64 encoding is designed to represent arbitrary sequences of octets in a form that requires case sensitivity but need not be humanly readable.
A 65-character subset of US-ASCII is used, enabling 6 bits to be represented per printable character.(The extra 65th character, "=",is used to signify a special processing function.)
Here we have the Base64 characters map:
64-character subset :ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/
Extra character :=

Base64 encoding takes three bytes (each byte consisting of eight bits) and represents them as four printable characters in the ASCII standard.
These transformations are making in two steps:
This two-step process is applied to the whole sequence of bytes that are encoded.
If the size of the original buffer is not multiple of three we should add one or two octets. For proper encoding the buffer length should be multiple of 3.
These bytes (one or two) will be equal with ‘0’. In this way we have created a 3-byte group. These artificial values ‘0’ cannot be encoded using the encoded table . They are represented by a 65th character. This character is ‘=’ and it can only appear at the end of encoded data.
Class definition
Base64 map initialization
The encode function
The decode function
Using this class
For more information about Base64, I suggest consulting the various RFCs. Base 64 is described in RFC 1521, http://www.ietf.org/rfc/rfc1521.txt?number=1521.
This article, along with any associated source code and files, is licensed under The Intelliproject Open License (IPOL)
| Silviu Caragea
| Silviu Caragea is the Founder, Administrator and Chief Editor who wrote and runs The IntelliProject. He's been programming since 2000 and now he's student at The Faculty of Economic Cybernetics, Statistics and Informatics from Bucharest. In the same time he's working as software developer at Cratima Software, a Romanian software and web design company that activates both on the local and foreign market, providing its customers with software development services, internet and intranet solutions, web design, graphic design and IT consultancy. His programming experience includes: - C,C++, Visual C++(Win32 API, MFC, ADO, STL, DAO, ODBC, ATL, COM, DirectShow, DirectDraw, WTL) - Open Source libraries :CURL & Boost - HTML, CSS - Java (SE,ME) - JavaScript, Ajax, Google Web Toolkit (GWT) - Php, MySQL -Oracle, PL SQL - C# .NET -Objective C, IPhone SDK, Cocoa Location: |
Sign up to post message on the article message board!