-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathbase62x_test.py
executable file
·66 lines (51 loc) · 1.84 KB
/
base62x_test.py
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
#!/usr/bin/python3
#-*- coding: utf-8 -*-
# -Base62x in -Python, testing
# Wadelau@{ufqi,gmail,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
# since Mon Mar 4 08:28:16 GMT 2019
import sys
import time
from datetime import date, datetime
import logging as logx
import random
# self define modules
sys.path.append("./") # pay attention!
from Base62x import Base62x
config = {};
base62x = Base62x(config);
#base62x2 = Base62x();
rawstr = "abcd1234x'efg89;01";
rawstr = 'var _tkd = _tkd || []; //点击量统计用';
rawstr2 = "abcd中文1234北京456;7-890";
encstr = base62x.encode(rawstr);
encstr2 = base62x.encode(rawstr2);
decstr = base62x.decode(encstr);
decstr2 = base62x.decode(encstr2);
print("rawstr:[{}] encstr:[{}] decstr:[{}] eq:[{}]".format(rawstr, encstr, decstr, (rawstr==decstr)));
print("2nd rawstr:[{}] encstr:[{}] decstr:[{}] eq:[{}]".format(rawstr2, encstr2, decstr2, (rawstr2==decstr2)));
a = 101010;
for i in range(2, 37):
b = int(str(a), i);
#print("i:{} b:{:02x} b10:{} a:{}".format(i, b, b, a));
ibase = 60; succc = 0; failc = 0; num = 0;
while num < 10000000:
for ibase in range(10, 62):
a = num;
encstr = base62x.encode(a, ibase);
decstr = base62x.decode(encstr, ibase);
if str(a) == str(decstr):
succc += 1;
else:
failc += 1;
print("ibase:{} a:{} encstr:{} decstr:{} eq:{} succ:{} fail:{}".format(ibase, a, encstr, decstr, (str(a)==str(decstr)), succc, failc));
randi = random.randint(0, 10000);
num += randi;
ibase = 16;
encstr = base62x.encode(a, ibase);
decstr = base62x.decode(encstr, ibase);
print("ibase:{} a:{} encstr:{} decstr:{}".format(ibase, a, encstr, decstr));