#! /usr/bin/python #-*- Encoding:UTF-8 -*- # Copyright (C) 2006-2011 the Hashzor authors and contributors # # This module is part of hashzor and is released under # the GPL License: http://www.gnu.org/licenses/gpl.html __version__ = "0.2.3" __author__ = [ "Lucas Fernandez" ] __license__ = "GNU General Public License" import re, os, gzip, httplib, operator, hashlib, subprocess class Hashzor: path = "" hash = "" type = "" hash_t = {'md5':32,'sha1':40} def __init__(self, hash, path='/volumes/data3/'): self.path = path self.hash = hash self.type = self.what_hash() def what_hash(self): for h in self.hash_t: if len(self.hash) == self.hash_t[h]: return h return False def pown_hash(self): path=self.path+"%s/%s/%s.%s.db.gz" % (self.type,self.hash[0],self.hash[:3],self.type) r=re.compile("^%s" % self.hash[3:], re.I) if not os.path.exists(path): return (-1,'(404) Fuck : Database not found for this hash function :-s') db = subprocess.Popen('gunzip -dc %s' % (path), stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) for lines in db.stdout.readlines(): l = lines.rstrip() if r.match(l): return (0,l[int(self.hash_t[self.type]-3):].rstrip()) #"Le pass est : %s" % l[int(self.hash_t[self.type]-3):].rstrip() self.add_to_batch() return (-2,"(404) : Hash %s not found" % self.hash) def add_to_batch(self): if not self.type: return False f=open(self.path+'batch.%s.db' % self.type,'a') f.write(self.hash+"\n") f.close() return True if __name__ == "__main__": h = Hashzor("555eb167ad4b65b3b3ab08210f1b823e") print h.pown_hash() h = Hashzor("555e477dad904395d6a85656918bd8a6") print h.pown_hash()