diff options
Diffstat (limited to 'koddecoder.py')
-rw-r--r-- | koddecoder.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/koddecoder.py b/koddecoder.py index b98ffe6..6489a88 100644 --- a/koddecoder.py +++ b/koddecoder.py | |||
@@ -25,8 +25,30 @@ KOD = [ | |||
25 | 0xfc, 0x84, 0xe5, 0xf9, 0x14, 0x19, 0xdf, 0x6e, 0x23, 0xc4, 0x66, 0xeb, | 25 | 0xfc, 0x84, 0xe5, 0xf9, 0x14, 0x19, 0xdf, 0x6e, 0x23, 0xc4, 0x66, 0xeb, |
26 | 0xcc, 0x22, 0x1c, 0x5c, | 26 | 0xcc, 0x22, 0x1c, 0x5c, |
27 | ] | 27 | ] |
28 | INV = [0] *256 | ||
29 | def calc_inverse(): | ||
30 | global INV | ||
31 | for i, x in enumerate(KOD): | ||
32 | INV[x] = i | ||
33 | |||
28 | def kodecode(o, data): | 34 | def kodecode(o, data): |
35 | """ | ||
36 | decode : shift, a[0]..a[n-1] -> b[0]..b[n-1] | ||
37 | |||
38 | b[i] = KOD[a[i]]- (i+shift) | ||
39 | """ | ||
29 | global KOD | 40 | global KOD |
30 | return bytes((KOD[b] - i - o)%256 for i, b in enumerate(data)) | 41 | return bytes((KOD[b] - i - o)%256 for i, b in enumerate(data)) |
31 | 42 | ||
43 | def koencode(o, data): | ||
44 | """ | ||
45 | encode : shift, b[0]..b[n-1] -> a[0]..a[n-1] | ||
46 | |||
47 | a[i] = INV[b[i]+ (i+shift)] | ||
48 | |||
49 | """ | ||
50 | global INV | ||
51 | return bytes(INV[(b + i + o)%256] for i, b in enumerate(data)) | ||
52 | |||
53 | calc_inverse() | ||
32 | 54 | ||