From 277f905849f9a050089049b2c84c45fac6203045 Mon Sep 17 00:00:00 2001 From: itsme Date: Fri, 9 Jul 2021 17:13:12 +0200 Subject: koddecoder: added koencode --- koddecoder.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/koddecoder.py b/koddecoder.py index b98ffe6..6489a88 100644 --- a/koddecoder.py +++ b/koddecoder.py @@ -25,8 +25,30 @@ KOD = [ 0xfc, 0x84, 0xe5, 0xf9, 0x14, 0x19, 0xdf, 0x6e, 0x23, 0xc4, 0x66, 0xeb, 0xcc, 0x22, 0x1c, 0x5c, ] +INV = [0] *256 +def calc_inverse(): + global INV + for i, x in enumerate(KOD): + INV[x] = i + def kodecode(o, data): + """ + decode : shift, a[0]..a[n-1] -> b[0]..b[n-1] + + b[i] = KOD[a[i]]- (i+shift) + """ global KOD return bytes((KOD[b] - i - o)%256 for i, b in enumerate(data)) +def koencode(o, data): + """ + encode : shift, b[0]..b[n-1] -> a[0]..a[n-1] + + a[i] = INV[b[i]+ (i+shift)] + + """ + global INV + return bytes(INV[(b + i + o)%256] for i, b in enumerate(data)) + +calc_inverse() -- cgit v1.2.3