1234567891011121314151617181920212223242526 |
- def decode(encoded_str):
- ''' Decode Base91 string to a bytearray '''
- v = -1
- b = 0
- n = 0
- out = bytearray()
- for strletter in encoded_str:
- if not strletter in decode_table:
- continue
- c = decode_table[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
|