-
Notifications
You must be signed in to change notification settings - Fork 13
/
base62x_test.cpp
105 lines (88 loc) · 2.36 KB
/
base62x_test.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
103
104
105
/*
* -Base62x test in C++
* need Base62x.class.hpp
* Wadelau@{ufqi,hotmail}.com
* Refers to
http://ieeexplore.ieee.org/xpl/freeabs_all.jsp?arnumber=6020065
-GitHub-Wadelau , base62x.c
https://github.com/wadelau/Base62x
https://ufqi.com/dev/base62x/?_via=-naturedns
* v1.2, Mon Feb 17 03:26:48 UTC 2020
* @todo, not ready!
*/
# include <iostream>
# include <string>
# include <cstring>
# include <sstream>
# include <cstdlib>
# include "Base62x.class.hpp"
using namespace std;
int isdebug = 1; /* output more details? */
//- app entry
int main(int argc, char *argv[]){
static const float ver = 1.2; // Mon Feb 17 03:38:49 UTC 2020
if(argc<3){
cout << "Usage: " << argv[0] << " [-v] [-n <2|8|10|16|32|36|60|62>] <-enc|dec> string\n";
cout << "Version: " << ver << "\n";
return 1;
}
Base62x myb62x; // main obj
int i = 0;
char *tmpin = argv[argc-1]; // src from command line
stringstream strval;
strval << tmpin;
unsigned char *input;
strval >> input;
char *code; //argv[1];
int asctype = 0; // for ascii
int issetv = 0; // verbose
int issetn = 0; // num conv
int fbase = 0; // from num base
int codetype = myb62x.codetype;
string enc = myb62x.enc;
string dec = myb62x.dec;
string deg = myb62x.deg;
string cvtn = myb62x.cvtn;
for(i=0; i<argc; i++){
code = argv[i];
if(code==cvtn){
issetn = 1; i++;
fbase = atoi(argv[i]);
if(isdebug){
cout << "--xx-- code:[" << code << "] fbase:[" << fbase << "] " << argv[i] << "\n";
}
}
else if(code==deg){
issetv = 1;
isdebug = 1;
}
else if(code==enc){
if(isdebug){
cout << "it is to enc!\n";
}
}
else if(code==dec){
if( isdebug){
cout << "it is to dec!\n";
}
codetype = 1;
}
}
int inputlen = strlen(tmpin); // input
int inputlenx = strnlen(tmpin, inputlen+1); // try to contain null byte
inputlen = inputlenx>(inputlen+1) ? inputlenx : inputlen;
int arrsize = (int)inputlen * 2; // log(fbase) / log(xpos) + 1;
unsigned char output[arrsize]; //*output[ arrsize ]
//- for enc
//output = myb62x.encode(input, fbase);
//- for dec
int obase = fbase;
//output = myb62x.decode(input, obase);
cout << "Hello Wolrd!" << argc << "\n";
cout << "\n";
for(int i=1; i<argc; i++){
string arg = argv[i];
cout << i << ": " << arg << "\n";
}
return 0;
}