Skip to content

Instantly share code, notes, and snippets.

@KenjiTakahashi
Created February 13, 2013 13:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KenjiTakahashi/4944485 to your computer and use it in GitHub Desktop.
Save KenjiTakahashi/4944485 to your computer and use it in GitHub Desktop.
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