Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ashutosh1206
GitHub Repository: ashutosh1206/crypton
Path: blob/master/Message-Authentication-Code/CBC-MAC-Forgery/Challenges/He-Moron/server.py
1402 views
1
from Crypto.Cipher import AES
2
from Crypto.Util.strxor import strxor
3
from binascii import hexlify, unhexlify
4
5
def sign(key, message):
6
try:
7
ECB = AES.new(key, AES.MODE_ECB)
8
messageblocks = [message[i:i + 16] for i in range(0, len(message), 16)]
9
tag = ECB.encrypt(messageblocks[0])
10
for i in range(1,len(messageblocks)):
11
tag = ECB.encrypt(strxor(messageblocks[i], tag))
12
return hexlify(tag)
13
except:
14
print("\nYou can't sign that way! No padding done here boy!")
15
exit()
16
17
if __name__ == '__main__':
18
19
flag = "\nWhat? Nooooooooo!!! xiomara{1_b0w_d0wn_70_y0u!}"
20
key = b'YELLOW SUBMARINE'
21
print("\nYou wanna challenge me? You trying to break my signing scheme? LOLLLLLL ><")
22
print("Anyways, try hard for that boy!")
23
print("Press 0 to get your message signed and 1 to submit a forgery...Pffff! Seriously?")
24
while(True):
25
try:
26
inp = raw_input("\n")
27
if(inp=="0"):
28
hex_msg = raw_input("\nGimme your hex encoded message\n")
29
msg = unhexlify(hex_msg)
30
hex_tag = sign(key, msg)
31
print("\nThere you go! Here's my hex encoded tag!")
32
print(hex_tag)
33
else:
34
print("\nOh! So, you are up for it?")
35
print("\nAlright! Gimme just two different hex encoded messages that could sign to the same tag!")
36
msg1 = unhexlify(raw_input("\nMessage #1: \n"))
37
msg2 = unhexlify(raw_input("\nMessage #2: \n"))
38
if(msg1 == msg2):
39
print("\nI am not fool boy! Get back and do the job like a grown up!")
40
exit()
41
if(msg1 != msg2 and sign(key, msg1)==sign(key, msg2)):
42
print(flag)
43
exit()
44
else:
45
print("\nOops! They don't match! Told ya! Hard work my son...Better luck next time!")
46
exit()
47
except:
48
exit()
49
50