Skip to content

Instantly share code, notes, and snippets.

@heyimalex
Last active December 23, 2015 05:39
Show Gist options
  • Save heyimalex/6588349 to your computer and use it in GitHub Desktop.
Save heyimalex/6588349 to your computer and use it in GitHub Desktop.
Short script to generate something like a tripcode securely from a string. Security dependent on length (and secretness) of your secret key.
from hashlib import sha512
import hmac
import string
# random key, generated with os.urandom(20)
secret_key = 'y6!n\xe1\x15\x96\x8c\xe8VX:\xa7\ta\xe6c\xf9\x04+'
# charset to use in tripcode
charset = string.ascii_letters + string.digits + '$#!@%&*'
# tripcode length
length = 10
def tripp(code):
raw = hmac.new(secret_key, code, sha512).digest()
ascii = ''.join(charset[int(ord(byte)/256.0*len(charset))] for byte in raw)
return ascii[:length]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment