From The Compiler, 6 Years ago, written in Python.
Embed
  1. def b64_md5(string):
  2.         md5 = hashlib.md5(string.encode('UTF-8')).digest()
  3.  
  4.         altchars = '98'.encode('ASCII')
  5.         b64 = base64.b64encode(md5, altchars)
  6.         b64 = b64.decode('ASCII').replace('=', 'A')
  7.  
  8.         return(b64)
  9.  
  10. def sgp_gen(pwd, length):
  11.         if not (4 <= length <= 24):
  12.                 raise ValueError("length needs to be between 4 and 24!")
  13.         for i in range(10):
  14.                 pwd = b64_md5(pwd)
  15.  
  16.         while not re.match('^[a-z].*[A-Z0-9].*', pwd[:length]):
  17.                 pwd = b64_md5(pwd)
  18.  
  19.         return(pwd[:length])
  20.  
  21. def sgp(domain, password, length=10, salt=""):
  22.         pwd = password + salt + ':' + domain
  23.         pwd = sgp_gen(pwd, length)
  24.         return(pwd)
  25.