From bb7c939ae36943714325ab2e62058ff55dd289ea Mon Sep 17 00:00:00 2001 From: root Date: Fri, 7 Sep 2012 15:11:03 +0200 Subject: [PATCH] adding main file, decode only --- base91.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 base91.py diff --git a/base91.py b/base91.py new file mode 100644 index 0000000..e970a09 --- /dev/null +++ b/base91.py @@ -0,0 +1,38 @@ +import struct + +base91_alphabet = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', + 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', + 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', + 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '!', '#', '$', + '%', '&', '(', ')', '*', '+', ',', '.', '/', ':', ';', '<', '=', + '>', '?', '@', '[', ']', '^', '_', '`', '{', '|', '}', '~', '"'] + +decode_table = dict((v,k) for k,v in enumerate(base91_alphabet)) + +def decode(encoded_str): + v = -1 + b = 0 + n = 0 + out = bytearray() + for strletter in encoded_str: + if not strletter in dectable: + continue + c = dectable[strletter] + if(v < 0): + v = c + else: + v += c*91 + b |= v << n + n += 13 if (v & 8191)>88 else 14 + while True: + out += struct.pack('B', b&255) + b >>= 8 + n -= 8 + if not n>7: + break + v = -1 + if v+1: + out += struct.pack('B', (b | v << n) & 255 ) + return out + -- 2.30.2