-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.cpp
More file actions
87 lines (72 loc) · 2.96 KB
/
Copy pathexample.cpp
File metadata and controls
87 lines (72 loc) · 2.96 KB
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
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include "include/BaseXX/base16.hpp"
#include "include/BaseXX/base32.hpp"
#include "include/BaseXX/base64.hpp"
#include <string>
#include <vector>
#include <cstdint>
#include <iostream>
void base16_example(std::string input);
void base32_example(std::string input);
void base64_example(std::string input);
using namespace BaseXX;
int main()
{
std::string input;
std::cout << "Please input a string: ";
std::getline(std::cin, input);
base16_example(input);
base32_example(input);
base64_example(input);
return 0;
}
void base16_example(std::string input)
{
std::vector<uint8_t> input_bytes(input.begin(), input.end());
std::vector<uint8_t> decoding_bytes;
std::string encoding_str;
std::string decoding_str;
Base16 handler;
encoding_str = handler.encode(input_bytes);
decoding_bytes = handler.decode(encoding_str);
decoding_str = std::string(decoding_bytes.begin(), decoding_bytes.end());
std::cout << std::endl << "------------ Base16 ------------" << std::endl;
std::cout << "Encoding: " << encoding_str << std::endl;
std::cout << "Decoding: " << decoding_str << std::endl;
std::cout << "Is it the same: " << ((input == decoding_str) ? ("true") : ("false")) << std::endl;
}
void base32_example(std::string input)
{
std::vector<uint8_t> input_bytes(input.begin(), input.end());
std::vector<uint8_t> decoding_bytes;
std::string encoding_str;
std::string decoding_str;
// Base32 handler(Base32Type::HEX);
Base32 handler(Base32Type::DEFAULT);
encoding_str = handler.encode(input_bytes);
decoding_bytes = handler.decode(encoding_str);
decoding_str = std::string(decoding_bytes.begin(), decoding_bytes.end());
// You can use `handler.get_type()` to check the codec type.
std::cout << std::endl << "------------ Base32 ------------" << std::endl;
std::cout << "Encoding: " << encoding_str << std::endl;
std::cout << "Decoding: " << decoding_str << std::endl;
std::cout << "Is it the same: " << ((input == decoding_str) ? ("true") : ("false")) << std::endl;
}
void base64_example(std::string input)
{
std::vector<uint8_t> input_bytes(input.begin(), input.end());
std::vector<uint8_t> decoding_bytes;
std::string encoding_str;
std::string decoding_str;
// Base64 handler(Base64Type::URL);
// Base64 handler(Base64Type::PEM);
// Base64 handler(Base64Type::MIME);
Base64 handler(Base64Type::DEFAULT);
encoding_str = handler.encode(input_bytes);
decoding_bytes = handler.decode(encoding_str);
decoding_str = std::string(decoding_bytes.begin(), decoding_bytes.end());
// You can use `handler.get_type()` to check the codec type.
std::cout << std::endl << "------------ Base64 ------------" << std::endl;
std::cout << "Encoding: " << encoding_str << std::endl;
std::cout << "Decoding: " << decoding_str << std::endl;
std::cout << "Is it the same: " << ((input == decoding_str) ? ("true") : ("false")) << std::endl;
}