c@5: /**
c@5:  * base-n, 1.0
c@5:  * Copyright (C) 2012 Andrzej Zawadzki (azawadzki@gmail.com)
c@5:  * 
c@5:  * Permission is hereby granted, free of charge, to any person obtaining a copy
c@5:  * of this software and associated documentation files (the "Software"), to deal
c@5:  * in the Software without restriction, including without limitation the rights
c@5:  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
c@5:  * copies of the Software, and to permit persons to whom the Software is
c@5:  * furnished to do so, subject to the following conditions:
c@5:  * 
c@5:  * The above copyright notice and this permission notice shall be included in
c@5:  * all copies or substantial portions of the Software.
c@5:  * 
c@5:  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
c@5:  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
c@5:  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
c@5:  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
c@5:  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
c@5:  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
c@5:  * SOFTWARE.
c@5: **/
c@5: #include <cassert>
c@5: #include <cstring>
c@5: #include <iostream>
c@5: #include <iterator>
c@5: #include <string>
c@5: 
c@5: #include "basen.hpp"
c@5: 
c@5: int main()
c@5: {
c@5:     using namespace std;
c@5:     string in = "Man is distinguished, not only by his reason, but by this singular passion from other animals, which is a lust of the mind, that by a perseverance of delight in the continued and indefatigable generation of knowledge, exceeds the short vehemence of any carnal pleasure.";
c@5:     cout << in << endl;
c@5: 
c@5:     {
c@5:         string encoded;
c@5:         bn::encode_b64(in.begin(), in.end(), back_inserter(encoded));
c@5:         bn::decode_b64(encoded.begin(), encoded.end(), ostream_iterator<char>(cout, ""));
c@5:         cout << endl;
c@5:     }
c@5:     {
c@5:         string encoded;
c@5:         bn::encode_b32(in.begin(), in.end(), back_inserter(encoded));
c@5:         bn::decode_b32(encoded.begin(), encoded.end(), ostream_iterator<char>(cout, ""));
c@5:         cout << endl;
c@5:     }
c@5:     {
c@5:         string encoded;
c@5:         bn::encode_b16(in.begin(), in.end(), back_inserter(encoded));
c@5:         bn::decode_b16(encoded.begin(), encoded.end(), ostream_iterator<char>(cout, ""));
c@5:         cout << endl;
c@5:     }
c@5:     {
c@5:         string encoded = "#TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlz\n"
c@5:             "IHNpbmd1bGFyIHBhc3Npb24gZnJvbS@BvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2Yg\n"
c@5:             " dGhlIG1(pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGlu\n"
c@5:             "\rdWVkIGFuZCBpbmRlZmF0aWdhY*mxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRo\n"
c@5:             "ZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4";
c@5:         bn::decode_b64(encoded.begin(), encoded.end(), ostream_iterator<char>(cout, ""));
c@5:         cout << endl;
c@5:     }
c@5:     {
c@5:         // move the struct definition outside of main() for non-C++11 compilers
c@5:         struct b8_custom
c@5:         {
c@5:             static size_t group_length()
c@5:             {
c@5:                return 3;
c@5:             }
c@5: 
c@5:             static char encode(int index)
c@5:             {
c@5:                 const char* const dictionary = "01234567";
c@5:                 assert(index < strlen(dictionary));
c@5:                 return dictionary[index];
c@5:             }
c@5: 
c@5:             static char decode(char c)
c@5:             {
c@5:                 if (c >= '0' && c <= '7') {
c@5:                     return c - '0';
c@5:                 }
c@5:                 return -1;
c@5:             }
c@5:         };
c@5:         string encoded;
c@5:         bn::impl::encode<b8_custom>(in.begin(), in.end(), back_inserter(encoded));
c@5:         bn::impl::decode<b8_custom>(encoded.begin(), encoded.end(), ostream_iterator<char>(cout, ""));
c@5:         cout << endl;
c@5:     }
c@5: }
c@5: