Skip to content

Instantly share code, notes, and snippets.

@mdeous
Created January 27, 2011 16:38
Show Gist options
  • Save mdeous/798756 to your computer and use it in GitHub Desktop.
Save mdeous/798756 to your computer and use it in GitHub Desktop.
perl 2 py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
from base64 import b64decode
from struct import unpack
if len(sys.argv) != 2:
print("Usage: %s HASH" % sys.argv[0])
exit(1)
line = sys.argv[1]
line = line.lstrip('{SSHA}')
if len(line) != 40:
print("invalid length")
hashed = b64decode(line)
a, b, c, d, e, s1, s2 = unpack(">LLLLLLL", hashed)
salt_hex = "%08x%08x" % (s1, s2)
salt = ""
i = 0
while i < 15:
salt += chr(int('0x%s' % salt_hex[i:i+2], 16))
i += 2
print("%08x%08x%08x%08x%08x:%s" % (a, b, c, d, e, salt))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment