Skip to content

Instantly share code, notes, and snippets.

@ducnhse130201
Created May 2, 2018 07:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ducnhse130201/33d5b1fae4f40146e269f322c42e541a to your computer and use it in GitHub Desktop.
Save ducnhse130201/33d5b1fae4f40146e269f322c42e541a to your computer and use it in GitHub Desktop.
VigenereCipher(SecconQuals2016)
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