Open6

RFC4648 Base32 メモ

pomu0325pomu0325

The characters "0" and "O" are easily confused, as are "1", "l", and "I". In the base32 alphabet below, where 0 (zero) and 1 (one) are not present, a decoder may interpret 0 as O, and 1 as I or L depending on case. (However, by default it should not; see previous section.)

pomu0325pomu0325

decoders MAY chose to reject an encoding if the pad bits have not been set to zero.

pomu0325pomu0325
>>> import base64
>>> base64.b32decode("MVS=====")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/base64.py", line 249, in b32decode
    raise TypeError('Incorrect padding')
TypeError: Incorrect padding

pythonは厳しいな。

pomu0325pomu0325

encodeに関してはRFCにちゃんと書かれているけど、decodeについては実装依存な感じ。

pomu0325pomu0325

python再び

>>> base64.b32decode('MU======') # 01100 10100
'e'
>>> base64.b32decode('MV======') # 01100 10101
'e'
>>> base64.b32decode('MVS=====') # 01100 10101 10010
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/base64.py", line 249, in b32decode
    raise TypeError('Incorrect padding')
TypeError: Incorrect padding

pad bitsが0じゃなくても(MVの余り2bitsの01)デコードしてくれるけど3文字15bitsだとエラー投げる。