Skip to content

Instantly share code, notes, and snippets.

@AndyNovo
Created November 15, 2016 20:29
Show Gist options
  • Save AndyNovo/d5ab5a942f11c9d64c7933bfed35ad43 to your computer and use it in GitHub Desktop.
Save AndyNovo/d5ab5a942f11c9d64c7933bfed35ad43 to your computer and use it in GitHub Desktop.
import random
def shiftBy(c, n):
return chr(((ord(c) - ord('a') + n) % 26) + ord('a'))
def encode(raw, keyLength):
key = [random.randint(1,25) for i in range(keyLength)]
secret = "".join([shiftBy(raw[i], key[i % keyLength]) for i in range(len(raw))])
withSpaces = ''
for i in range(len(secret)):
if i % 5 == 4:
withSpaces = withSpaces + secret[i] + ' '
else:
withSpaces = withSpaces + secret[i]
return withSpaces, key
code,key = encode("andyisthegreatest", 3)
print code, key
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment