phpPython/0000755000175000017500000000000010524154414012041 5ustar brycebrycephpPython/phpPart1.php0000755000175000017500000000035710524163306014261 0ustar brycebryce#!/usr/bin/php phpPython/main.sh0000755000175000017500000000021610524031762013323 0ustar brycebryce#!/bin/sh start=`date +%s` ./phpPart1.php | ./python.py | ./phpPart2.php finish=`date +%s` echo 'Completion Time:' `expr $finish - $start`s phpPython/python.py0000755000175000017500000000300610524164035013736 0ustar brycebryce#!/usr/bin/python import sys,threading,md5,Queue # This is the threaded class class Process(threading.Thread): def __init__(self,ids,results): threading.Thread.__init__(self) self.ids = ids self.results = results def run(self): while True: # Once ids is empty stop the thread if self.ids.empty(): break # The queue can become empty inbetween # the previous check and now, so set # 1 second timeout and handle the error # returned. # The except block could break there, but since # it is handled above we will just continue. try: t = self.ids.get(True,1) except Queue.Empty: continue p = breakHash(t) self.results.put(p) # This brute forces the original string from the hash. def breakHash(hash): for x in range(3000): if md5.new(str(x)).hexdigest() == hash: return hash,x return hash,1 def main(): # Create blocking queue from input ids = Queue.Queue(0) for line in sys.stdin: ids.put(line[:-1]) # Create blocking queue for output results = Queue.Queue(ids.qsize()) # Create and start all threads myThreads = [] for x in range(3): c = Process(ids,results) myThreads.append(c) c.start() # The main() thread will stay here until # all other threads are complete for thread in myThreads: thread.join() # Get the results and send them to the next function for x in range(results.qsize()): t = results.get() # Handle error if pipe is closed try: print t[0],"\t",t[1] except IOError: sys.exit(1) if __name__ == '__main__': main()phpPython/README0000644000175000017500000000033310524154414012720 0ustar brycebryceCombining php and python Note: Each of these files needs execute permission by the calling user. Also ensure the #! declaration at the top of each corresponds properly to the location of these binaries on your system.phpPython/phpPart2.php0000755000175000017500000000024410524031557014257 0ustar brycebryce#!/usr/bin/php