Created
November 15, 2016 20:29
-
-
Save AndyNovo/d5ab5a942f11c9d64c7933bfed35ad43 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 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