Skip to content

Instantly share code, notes, and snippets.

@JohnnyJayJay
Created September 2, 2019 17:15
Show Gist options
  • Save JohnnyJayJay/99188e14861ad7d04fe7c0501a8a5522 to your computer and use it in GitHub Desktop.
Save JohnnyJayJay/99188e14861ad7d04fe7c0501a8a5522 to your computer and use it in GitHub Desktop.
vigenere cipher hacking script
import math
def duplicates(vigenere):
strings = []
duplicates = set()
for index in range(len(vigenere)):
string = ""
for i in range(3):
if index + i < len(vigenere):
string += vigenere[index + i]
if string in strings:
duplicates.add(string)
strings.append(string)
return duplicates
def spacings(vigenere, duplicate):
spacings = []
for i in range(vigenere.count(duplicate)):
first_occurence = vigenere.index(duplicate)
vigenere = vigenere[(first_occurence + 3):]
second_occurence = vigenere.find(duplicate)
if second_occurence != -1:
second_occurence += first_occurence + 3
spacings.append(second_occurence - first_occurence)
return spacings
def divisors(number):
divisors = []
current_divisor = 2
while current_divisor <= number / 2:
if number % current_divisor == 0:
divisors.add(current_divisor)
current_divisor += 1
return divisors
encrypted = """
KELXTNAZYXJYVGYNRFWANEWCHZCJVR
UHCSEHZAOXKEVSMJVFAAXYIEOANYIN
SLXNIZLNMHLRUUHIMUYGYYYRZANYIE
ZPCYDGLKYHOQLNMHLAHBYQYAKPZNJS
ZIWMANZIHXSUYELPEZZIWMLVLRQJMG
KRUZWFLNQNIRPNYQIEJHYASELRNWES
OIYWEHJHGFRPORCSHIPEBXEUHUWMQN
UCBMEHMEHRMFAELXEUKAMXIFDOUSHR
YSUZGUUIWMXIPEFFRQLRMNWGOECSDR
YHUWHG
""".upper().replace("\n", "")
for duplicate in duplicates(encrypted):
print(f'{duplicate}: {spacings(encrypted, duplicate)}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment