Skip to content

Instantly share code, notes, and snippets.

@scottchiefbaker
Created April 30, 2018 16:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scottchiefbaker/b011b7e4d98204d575b36fad654106e1 to your computer and use it in GitHub Desktop.
Save scottchiefbaker/b011b7e4d98204d575b36fad654106e1 to your computer and use it in GitHub Desktop.
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