''' Created on Mar 9, 2015 @author: Brett Paufler Copyright Brett Paufler As of 3-13-15 this was all play, posted to weekly Python code CAN KILL ''' import hashlib import numpy as np from collections import defaultdict #NUMPY #np.binary_repr(10,8) def hash_test(): name = 'Brett Paufler' vH = 898607709 h = hash(name) print h print h == vH print hex(h) print int(hex(h),16) s = hashlib.sha1(name).hexdigest() sHi = 578165085125245727718998854406463011907786567518 print print s print int(s,16) print sHi == int(s,16) def webHash(text): def c_mul(a,b): return eval(hex(long(a)*b & 0xFFFFFFFFL)[:-1]) value = ord(text[0]) << 7 for n in text: value = c_mul(1000003,value) ^ ord(n) value = value ^ len(text) if value == -1: value = -2 return value #print webHash('Brett Paufler') #BEGIN BITWISE # BITWISE #a = 13 #b = -13 c = [(13,13), ('13<<2',13<<2), ('13>>2',13>>2), (' ',0), ('13|~13', 13|~13), ('13&~13', 13&~13), ('13^~13', 13^~13), ] for k,v in c: if k == ' ': print else: print "{: <10}\tNum: {: >4} \t numpy: {: >10} \t Python: {: >10} ".format( k, v, np.binary_repr(v,8), bin(v)) #"{:0>4}".format(1)