Skip to content

Instantly share code, notes, and snippets.

@yarjor
Created September 29, 2018 17:48
Show Gist options
  • Save yarjor/5b9e08be4643c7bbf64e09ff6a67329b to your computer and use it in GitHub Desktop.
Save yarjor/5b9e08be4643c7bbf64e09ff6a67329b to your computer and use it in GitHub Desktop.
[Differentiate ECB/CBC] #oracle #detection #crypto #blockcipher #cbc #ecb
def detect_cipher(cipher_box):
chosen_plaintext = 'a' * 16 * 6
cipher_text = cipher_box(chosen_plaintext)
cipher_blocks = divide_blocks(cipher_text, 16)
if len(cipher_blocks) != len(set(cipher_blocks)):
return 'ECB'
else:
return 'CBC'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment