Created
May 2, 2018 07:36
-
-
Save ducnhse130201/33d5b1fae4f40146e269f322c42e541a to your computer and use it in GitHub Desktop.
VigenereCipher(SecconQuals2016)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from hashlib import * | |
import random | |
import itertools | |
h = 'f528a6ab914c1ecf856a1d93103948fe' | |
alpha = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ{}' | |
cipher = 'LMIG}RPEDOEEWKJIQIWKJWMNDTSR}TFVUFWYOCBAJBQ' | |
format_flag = 'SECCON{' | |
def repeat(a,len_b): | |
return (a*(int(len_b/len(a))+1))[:len_b] | |
def decode_vigenere(cipher,key,alpha): | |
if len(key) < len(cipher): | |
key = repeat(key,len(cipher)) | |
plain = '' | |
for i in range(len(cipher)): | |
num = alpha.index(cipher[i]) - alpha.index(key[i]) | |
if num < 0: | |
num = num + len(alpha) | |
plain += alpha[num] | |
return plain | |
key = 'VIGENERE' | |
possible_keys = [''.join(i) for i in itertools.product(alpha,repeat = 4)] | |
for c in possible_keys: | |
key = key + c | |
plaintext = decode_vigenere(cipher,key,alpha) | |
if md5(plaintext).hexdigest() == h: | |
print plaintext | |
break | |
key = 'VIGENERE' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment