Last active
December 23, 2015 05:39
-
-
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.
This file contains hidden or 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
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