myano / fs-decrypt.py secret
Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist
View fs-decrypt.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
#!/usr/bin/env python
 
 
import string
 
new_alphabet = string.lowercase
top_right_alphabet = new_alphabet.replace('q', '')
 
new_alphabet = top_right_alphabet
 
keyword_one = 'exampl'
keyword_two = 'keyword'
encrypted_text = 'FYGMKYHOBXMFKKKIMD'
 
for char in keyword_one:
top_right_alphabet = top_right_alphabet.replace(char, '')
top_right = keyword_one + top_right_alphabet
 
 
bottom_left_alphabet = new_alphabet
for char in keyword_two:
bottom_left_alphabet = bottom_left_alphabet.replace(char, '')
bottom_left = keyword_two + bottom_left_alphabet.replace('q', '')
 
n = 5
 
bottom_left = [bottom_left[i:i+n] for i in range(0, len(bottom_left), 5)]
top_right = [top_right[i:i+n] for i in range(0, len(top_right), 5)]
new_alphabet_rows = [new_alphabet[i:i+n] for i in range(0, len(new_alphabet), 5)]
 
print 'top_right:'
p = 0
for each in top_right:
print '\t%s\t%s' % (new_alphabet_rows[p], each)
p += 1
 
print 'bottom_left:'
q = 0
for each in bottom_left:
print '\t%s\t%s' % (each, new_alphabet_rows[q])
q += 1
 
 
original_message = str()
 
k = 0
while k < len(encrypted_text):
one = encrypted_text[k]
two = encrypted_text[k + 1]
 
one_pos = ''.join(top_right).find((one).lower())
two_pos = ''.join(bottom_left).find((two).lower())
 
one_col = one_pos % 5
if one_col == 0 or one_col == 5:
one_row = one_pos / 5
else:
one_row = (one_pos / 5)
 
two_col = two_pos % 5
if two_col == 0 or two_col == 5:
two_row = two_pos / 5
else:
two_row = (two_pos / 5)
 
 
first_out_char = new_alphabet_rows[one_row][two_col]
second_out_char = new_alphabet_rows[two_row][one_col]
 
original_message += first_out_char + second_out_char
k += 2
 
print (original_message).upper()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.