-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
102 lines (93 loc) · 2.29 KB
/
main.cpp
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include<iostream>
#include<map>
using namespace std;
/*
* Encoded values defined in RFC 4648:
* https://datatracker.ietf.org/doc/html/rfc4648#section-4
* example usage: `g++ main.cpp -o main && ./main 'Hi world! My name is Arjun'`
*/
const char *padding = "=";
map<char, string> encodedMap = {
{ 'A', "000000",},
{ 'B', "000001",},
{ 'C', "000010",},
{ 'D', "000011",},
{ 'E', "000100",},
{ 'F', "000101",},
{ 'G', "000110",},
{ 'H', "000111",},
{ 'I', "001000",},
{ 'J', "001001",},
{ 'K', "001010",},
{ 'L', "001011",},
{ 'M', "001100",},
{ 'N', "001101",},
{ 'O', "001110",},
{ 'P', "001111",},
{ 'Q', "010000",},
{ 'R', "010001",},
{ 'S', "010010",},
{ 'T', "010011",},
{ 'U', "010100",},
{ 'V', "010101",},
{ 'W', "010110",},
{ 'X', "010111",},
{ 'Y', "011000",},
{ 'Z', "011001",},
{ 'a', "011010",},
{ 'b', "011011",},
{ 'c', "011100",},
{ 'd', "011101",},
{ 'e', "011110",},
{ 'f', "011111",},
{ 'g', "100000",},
{ 'h', "100001",},
{ 'i', "100010",},
{ 'j', "100011",},
{ 'k', "100100",},
{ 'l', "100101",},
{ 'm', "100110",},
{ 'n', "100111",},
{ 'o', "101000",},
{ 'p', "101001",},
{ 'q', "101010",},
{ 'r', "101011",},
{ 's', "101100",},
{ 't', "101101",},
{ 'u', "101110",},
{ 'v', "101111",},
{ 'w', "110000",},
{ 'x', "110001",},
{ 'y', "110010",},
{ 'z', "110011",},
{ '0', "110100",},
{ '1', "110101",},
{ '2', "110110",},
{ '3', "110111",},
{ '4', "111000",},
{ '5', "111001",},
{ '6', "111010",},
{ '7', "111011",},
{ '8', "111100",},
{ '9', "111101",},
{ '+', "111110",},
{ '/', "111111",},
};
const int MAX_INP_LEN = 128;
int main(int argc, char **argv) {
string word;
if (argc < 2) {
cout << "Give the value you want to encoded as an argument" << endl;
} else {
word = argv[1];
string result;
for (int i = 0; i < word.length(); i++) {
const char unencodedChar = word[i];
// TODO what if char is not in the encoded map?
const string encodedVal = encodedMap[unencodedChar];
result.append(encodedVal);
}
cout << result << endl;
}
return 0;
};