Advertisement
Guest User

hash generator

a guest
Jun 1st, 2012
425
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.51 KB | None | 0 0
  1. # coding=utf-8
  2.  
  3. import os
  4. import hashlib
  5. import binascii
  6.  
  7. hashdir = "./hc-testing"
  8.  
  9. passwords = [ '1',
  10.         '4ä',
  11.         'LL+',
  12.         'M45m',
  13.         '++=z6',
  14.         'U!Nzc4',
  15.         'fbz4ö!f',
  16.         '=c4m8tN2',
  17.         'YM8346bFD',
  18.         '::c345nb§V',
  19.         '<Xw34b)"f+r',
  20.         'Nvoi6456nbGF',
  21.         'LKJN1v^nvb$bC',
  22.         ')M4b6nUbpLw000',
  23.         '9348b5npBNZ5nk4',
  24.         'kj5093Nßchn34V3,',
  25.         'l8zNVB54!n5á6L"nb', ]
  26.  
  27. hex = binascii.hexlify
  28. unhex = binascii.unhexlify
  29.  
  30. def writeDict(filename="dict"):
  31.     """Save dictionary in the hashdir"""
  32.     handle=open(os.path.join(hashdir, filename), "w+")
  33.     for pw in passwords:
  34.         handle.write(pw+"\n")
  35.     handle.close()
  36.  
  37. def loadDict(file):
  38.     """Load passwords from file, doNät use the build in ones"""
  39.     global passwords
  40.     with open(file) as handle:
  41.         passwords = handle.readlines()
  42.         passwords = map(lambda x: x.strip("\r\n"), passwords)
  43.  
  44. class hashwrapper(object):
  45.     """Interface"""
  46.     def __init__(self, salt):
  47.         self.salt = salt
  48.         self.realSalt = salt
  49.         self.hashobj = hashlib.md5()
  50.    
  51.     def updateSalt(self, newSalt):
  52.         self.salt = newSalt
  53.         self.realSalt = newSalt
  54.    
  55.     def update(self, passwd):
  56.         raise(UserWarning("Implementation error, "+
  57.             "update() has to be overwritten!"))
  58.    
  59.     def digest(self):
  60.         return self.hashobj.digest()
  61.  
  62. class wrap_m10(hashwrapper):
  63.     """md5(md5($pass).md5($salt))"""
  64.     def __init__(self, salt="abcdef"):
  65.         hashwrapper.__init__(self, salt)
  66.         self.updateSalt(self.salt)
  67.    
  68.     def updateSalt(self, newSalt):
  69.         hashwrapper.updateSalt(self, newSalt)
  70.         updateSalt = hashlib.md5()
  71.         updateSalt.update(self.salt)
  72.         self.salt = hex(updateSalt.digest())
  73.    
  74.     def update(self, passwd):
  75.         pw = hashlib.md5()
  76.         pw.update(passwd)
  77.         self.hashobj.update(hex(pw.digest())+self.salt)
  78.  
  79. class wrap_m11(hashwrapper):
  80.     """Joomla"""
  81.     def __init__(self, salt="abcdef"):
  82.         hashwrapper.__init__(self, salt)
  83.    
  84.     def update(self, passwd):
  85.         self.hashobj.update(passwd+self.salt)
  86.  
  87. class wrap_m21(hashwrapper):
  88.     """OSC"""
  89.     def __init__(self, salt="abcdef"):
  90.         hashwrapper.__init__(self, salt)
  91.    
  92.     def update(self, passwd):
  93.         self.hashobj.update(passwd+self.salt)
  94.  
  95.  
  96. hashtypes = {   0:      hashlib.md5(),
  97.                 10:     wrap_m10(),
  98.                 11:     wrap_m11(),
  99.                 21:     wrap_m21(),
  100.                 100:    hashlib.sha1(),
  101.             }
  102.  
  103. if __name__=="__main__":
  104.     for mode in hashtypes:
  105.         handle=open(os.path.join(hashdir, str(mode)+".hash"), "w+")
  106.         for pw in passwords:
  107.             new = hashtypes[mode]
  108.             new.update(pw)
  109.             try:
  110.                 salt = ":"+new.realSalt+"\n"
  111.             except:
  112.                 salt = "\n"
  113.             handle.write(hex(new.digest())+salt)
  114.         handle.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement