-
-
Save s4w3d0ff/9d65ec5866d78842547183601b2fa4d5 to your computer and use it in GitHub Desktop.
create a tor hashed password without using `tor --hash-password`
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
from os import urandom | |
from binascii import b2a_hex | |
from hashlib import sha1 | |
def getTorPassHash(secret='password'): | |
''' | |
https://gist.github.com/jamesacampbell/2f170fc17a328a638322078f42e04cbc | |
''' | |
# static 'count' value later referenced as "c" | |
indicator = chr(96) | |
# generate salt and append indicator value so that it | |
salt = "%s%s" % (urandom(8), indicator) | |
c = ord(salt[8]) | |
# generate an even number that can be divided in subsequent sections. (Thanks Roman) | |
EXPBIAS = 6 | |
count = (16+(c&15)) << ((c>>4) + EXPBIAS) | |
d = sha1() | |
# take the salt and append the password | |
tmp = salt[:8]+secret | |
# hash the salty password | |
slen = len(tmp) | |
while count: | |
if count > slen: | |
d.update(tmp) | |
count -= slen | |
else: | |
d.update(tmp[:count]) | |
count = 0 | |
hashed = d.digest() | |
# Put it all together into the proprietary Tor format. | |
return '16:%s%s%s' % (b2a_hex(salt[:8]).upper(), | |
b2a_hex(indicator), | |
b2a_hex(hashed).upper()) | |
if __name__ == '__main__': | |
print(getTorPassHash(raw_input("Type something: "))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
NameError: name 'raw_input' is not defined