myano / fs-encrypt.py secret
Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist
View fs-encrypt.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 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
#!/usr/bin/env python
 
 
import random
import string
 
new_alphabet = string.lowercase
q_pos = new_alphabet.find('q')
top_right_alphabet = new_alphabet[:q_pos] + new_alphabet[q_pos + 1:]
 
new_alphabet = top_right_alphabet
 
keyword_one = 'exampl'
 
for char in keyword_one:
top_right_alphabet = top_right_alphabet.replace(char, '')
 
top_right = keyword_one + top_right_alphabet
 
keyword = 'keyword'
bottom_left_alphabet = string.lowercase
 
for char in keyword:
bottom_left_alphabet = bottom_left_alphabet.replace(char, '')
 
q_pos = bottom_left_alphabet.find('q')
bottom_left_alphabet = bottom_left_alphabet[:q_pos] + bottom_left_alphabet[q_pos + 1:]
bottom_left = keyword + bottom_left_alphabet
 
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
 
 
msg = "Help Me Obiwankenobi"
msg = msg.lower()
msg = msg.replace(' ', '')
 
encrypted_message = str()
 
k = 0
while k < len(msg):
one = msg[k]
two = msg[k + 1]
#print 'one:', one
#print 'two:', two
one_pos = new_alphabet.find(one)
two_pos = new_alphabet.find(two)
 
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 = top_right[one_row][two_col]
#print 'first_out_char', first_out_char
 
second_out_char = bottom_left[two_row][one_col]
#print 'second_out_char', second_out_char
 
encrypted_message += first_out_char + second_out_char
 
print ''
k += 2
 
 
print (encrypted_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.