-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.py
44 lines (30 loc) · 1008 Bytes
/
common.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
from config import Config
import psycopg2
class Bv2av(object):
table = 'fZodR9XQDSUm21yCkr6zBqiveYah8bt4xsWpHnJE7jL5VG3guMTKNPAwcF'
tr = {}
s = [11, 10, 3, 8, 4, 6]
xor = 177451812
add = 8728348608
def __init__(self):
for i in range(58):
self.tr[self.table[i]] = i
def dec(self, x):
"""bv2av"""
r = 0
for i in range(6):
r += self.tr[x[self.s[i]]] * 58 ** i
return (r - self.add) ^ self.xor
def enc(self, x):
"""av2bv"""
x = (x ^ self.xor) + self.add
r = list('BV1 4 1 7 ')
for i in range(6):
r[self.s[i]] = self.table[x // 58 ** i % 58]
return ''.join(r)
class DbBase():
def __init__(self):
self.connection = psycopg2.connect(database=Config.database, user=Config.user, password=Config.password, host=Config.host, port=Config.port)
self.cursor = self.connection.cursor()
def close(self):
self.connection.close()