/fs-encrypt.py Secret
Created
March 27, 2014 20:07
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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