Open6
RFC4648 Base32 メモ
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.)
decoders MAY chose to reject an encoding if the pad bits have not been set to zero.
>>> 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は厳しいな。
rubyのbase32 gemは変な桁数渡すとdecode壊れる。
> Base32.decode("MVS")
=> "\xAC"
encodeに関してはRFCにちゃんと書かれているけど、decodeについては実装依存な感じ。
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だとエラー投げる。