|
@@ -6,7 +6,7 @@ class keyRing:
|
|
|
|
|
|
def __init__(self, keyPath, dbEncoded, textsEncoded):
|
|
|
self.keyPath = keyPath
|
|
|
- self.vettSpec = self.getVettSpec(dbEncoded)
|
|
|
+ self.vettDictDec, self.vettDictEnc = self.getVettSpec(dbEncoded)
|
|
|
self.textKeys = self.getKeys(textsEncoded)
|
|
|
|
|
|
def getVettSpec(self, dbEncoded):
|
|
@@ -15,7 +15,17 @@ class keyRing:
|
|
|
with open(self.keyPath + "vettSpec.csv", 'r') as file1:
|
|
|
reader = csv.DictReader(file1)
|
|
|
vettSpec = [row for row in reader]
|
|
|
- return vettSpec
|
|
|
+ vettDictDec = {}
|
|
|
+ vettDictEnc = {}
|
|
|
+ for index, entry in enumerate(vettSpec):
|
|
|
+ if index==0:
|
|
|
+ continue
|
|
|
+ vettDictDec[chr(int(entry['intcode']))] = chr(int(entry['unicode'], 16))
|
|
|
+ vettDictEnc[chr(int(entry['unicode'], 16))] = chr(int(entry['intcode']))
|
|
|
+
|
|
|
+ vettDictEnc['\\%'] = "%"
|
|
|
+ vettDictEnc['\\_'] = "_"
|
|
|
+ return vettDictDec, vettDictEnc
|
|
|
|
|
|
def getKeys(self, textsEncoded):
|
|
|
if not textsEncoded:
|
|
@@ -48,33 +58,24 @@ class keyRing:
|
|
|
|
|
|
|
|
|
|
|
|
-def db_decode(vettSpec, string0):
|
|
|
+def db_decode(vettDictDec, string0):
|
|
|
+ return ''.join([vettDictDec[char] for char in string0])
|
|
|
|
|
|
- res = ""
|
|
|
- for char0 in string0:
|
|
|
-
|
|
|
- char0Dec = ord(char0)
|
|
|
-
|
|
|
- char0ConvDec = next((el['unicode'] for el in vettSpec if el['intcode'] == str(char0Dec)), None)
|
|
|
-
|
|
|
- res += chr(int(char0ConvDec, 16))
|
|
|
- return res
|
|
|
|
|
|
-def db_encode(vettSpec, string0):
|
|
|
+def db_encode(vettDictEnc, string0):
|
|
|
res = ""
|
|
|
+ prevChar = ""
|
|
|
for char0 in string0:
|
|
|
-
|
|
|
-
|
|
|
- if char0 != "%" and "_":
|
|
|
-
|
|
|
-
|
|
|
- char0Hex = hex(ord(char0))
|
|
|
-
|
|
|
- char0ConvDec = next((el['intcode'] for el in vettSpec if el['unicode'] == char0Hex[2:].upper()), None)
|
|
|
-
|
|
|
- res += chr(int(char0ConvDec))
|
|
|
+ if char0=="\\":
|
|
|
+ prevChar = "\\"
|
|
|
+ continue
|
|
|
+ if prevChar!="\\":
|
|
|
+ res += vettDictEnc[char0]
|
|
|
else:
|
|
|
- res += char0
|
|
|
+ comp = "\\" + char0
|
|
|
+ add = vettDictEnc.get(comp) if vettDictEnc.get(comp) is not None else vettDictEnc["\\"] + vettDictEnc[char0]
|
|
|
+ res += add
|
|
|
+
|
|
|
return res
|
|
|
|
|
|
|