#!/usr/bin/python import sys import string sys.path.insert(0, 'build/lib.linux-i686-2.6') import pyrabinf_mod BUFSIZE=1024 def usage(retval): print >> sys.stderr, "Usage: %s " % sys.argv[0] print >> sys.stderr, "\tExample: %s testfile 16" % sys.argv[0] sys.exit(retval) def run_task(filename, windowsize): window = pyrabinf_mod.Window(windowsize) window.reset(); with open(filename, 'r') as file_: while True: block = file_.read(BUFSIZE) if not block: break for byte in (ord(char) for char in block): fingerprint = window.slide8(byte) & 0xfff; if chr(byte) in string.printable and byte != ord('\t') and byte != ord('\n'): print '%s\t' % chr(byte), else: print '0x%x\t' % byte, print "==>\t%d" % fingerprint def main(): if len(sys.argv) != 3: usage(1) # READ ARGUMENTS filename = sys.argv[1] windowsize = int(sys.argv[2]) # READ THE FILE AND COMPUTE RABIN FINGERPRINT run_task(filename, windowsize) main()