def Verify(Message, Key, hash): hashed = sha(Key + Message) if hash == hashed: return True return False # Message = "Hello, my name is Max" # print Message # Key = randKey() # hash = sha(Key + Message) # print Verify(Message, Key, hash) # Message = Message.replace("e", "d") # print Message # print Verify(Message, Key, hash) # print sha("Password") # binary = binascii.a2b_hex(sha("Hello World")) # print binascii.b2a_base64(binary)
fPad = 0 Padding = "1" while num % 512 != 448: num += 1 fPad += 1 Padding += "0" * fPad Padding += "{0:064b}".format(bits) Binary = [Padding[i:i+8] for i in range(0,len(Padding),8)] glueStr = "" for b in Binary: glueStr += chr(int(b,2)) return glueStr Str = "foo" encoded = encodeData(Str) dLen = len(encoded) Key = randKey() secret = sha(Key + encoded) Segments = [secret[i:i+8] for i in range(0,40,8)] Hex = [] for s in Segments: dec = int(s,16) Hex.append(dec) HackedStr = ";admin=true;password=true;" hack = hackedSha(HackedStr, Hex, (dLen + 16) * 8) print hack print sha(Key + encoded + reversePad(dLen,16) + HackedStr) CheckStr = encoded + reversePad(dLen, 16) + HackedStr print Verify(CheckStr, Key, hack) #print Verify(encoded, Key, secret)