Created
April 30, 2018 16:01
-
-
Save scottchiefbaker/b011b7e4d98204d575b36fad654106e1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import sys | |
# Make sure we have enough arguments to start | |
if len(sys.argv) != 3: | |
print("Usage: %s [base] [Sekrit Message]" % sys.argv[0]) | |
exit() | |
# Print out the letter base, and build the dictionary | |
dict = {} | |
for i in range(1,27): | |
char = chr(i + 96); | |
print("%d=%s" % (i,char), end = " ") # Print out the key | |
dict[char] = i # Store the char => number mapping in a dict | |
print("\n") | |
base = sys.argv[1] | |
string = sys.argv[2] | |
last = base # Starting number | |
for x in string: | |
if x == " ": # Skip spaces | |
continue | |
y = x.lower() | |
cur = dict[y] | |
# How far to jump to the next char | |
jump = int(cur) - int(last) | |
if jump < -13: # If it's too big negative we loop around | |
jump = 26 + jump | |
if jump > 13: # If it's too big positive then we go negative | |
jump = jump - 26 | |
print(jump, end=" ") | |
last = cur | |
print() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment