-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11.py
More file actions
18 lines (16 loc) · 684 Bytes
/
11.py
File metadata and controls
18 lines (16 loc) · 684 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
from ecboracle import *
#Encrypts a given plaintext using AES with ECB or CBC randomly chosen
#Key and IV (if necessary) are chosen at random
#Plaintext is padded with 5-10 bytes at beginning and end
def encryptRandomly(plaintext):
padding = generateRandomIV()
paddedText = padding[:random.randint(5, 10)]+plaintext+padding[random.randint(-10, -5):]
if random.random() >= 0.5:
#Encrypt under ECB
return aes.aesECBEncrypt(paddedText, generateRandomKey())
else:
#Encrypt under CBC
return aes.aesCBCEncrypt(paddedText, generateRandomKey(), generateRandomIV())
if __name__ == "__main__":
for i in range(10):
print "ECB" if determineIfOracleECB(encryptRandomly) else "CBC"