Skip to content

Instantly share code, notes, and snippets.

@Browne
Created January 18, 2015 23:44
Show Gist options
  • Select an option

  • Save Browne/bd0771bb032e5fb96b96 to your computer and use it in GitHub Desktop.

Select an option

Save Browne/bd0771bb032e5fb96b96 to your computer and use it in GitHub Desktop.
Vigenere with a known key
#!/usr/bin/env python
def crack(x, y):
"""For the length of string i, get the value of the character A=1, B=2 etc
Subtract this from the value of the code at the relevant position
Modulo 26 to remove an remainders/negatives."""
result = ""
for i in range(len(x)):
result += chr((((ord(x[i].lower())) - (ord(y[i % 21].lower()))) % 26) + 97).upper()
return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment