Skip to content

Instantly share code, notes, and snippets.

@prggmr
Last active August 29, 2015 14:05
Show Gist options
  • Save prggmr/a7b46fee526b140f8292 to your computer and use it in GitHub Desktop.
Save prggmr/a7b46fee526b140f8292 to your computer and use it in GitHub Desktop.
Token Generator using clientid and secret.
import hashlib
def gen_token(clientid, secret, length=512):
clientid_token = hashlib.sha512(clientid).hexdigest()
secret_token = hashlib.sha512(secret).hexdigest()
token = secret_token+clientid_token
token = hex(pow(int(str(token), 16), 2)).replace('0x','')
b = 1
# Change divisor +/- to increase / decrease length
div = 512/length
out = ''
for a in token:
if a == 'L':
a = '0'
if b % div==0:
if int(a, 16) < 5:
a = hex(int(a,16)+10).replace('0x','')
out = out+ a
b+=1
return out
generated = []
for a in range(1,1000000):
for b in range(1,20):
gen = gen_token(str(a), str(b), 64)
if gen in generated:
print "DUPLICATE"
generated.append(gen)
print len(gen)
print gen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment