Created
February 13, 2013 13:09
-
-
Save KenjiTakahashi/4944485 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import hashlib | |
from base64 import b64encode | |
def discid(toc): | |
u""" | |
'first':int, | |
'last':int, | |
'offsets':[int] | |
""" | |
discid=hashlib.sha1() | |
discid.update(('%02x'%toc['first']).upper()) | |
discid.update(('%02x'%toc['last']).upper()) | |
for i in toc['offsets']: discid.update(('%08x'%i).upper()) | |
for i in range(100-toc['first']-toc['last']): discid.update('%08x'%0) | |
return b64encode(discid.digest(),['.','_']).replace('=','-') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment