Created
March 8, 2015 21:59
-
-
Save daisylb/3b4d75ba039e6e455f7c to your computer and use it in GitHub Desktop.
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
VALID_CHARS = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789' | |
def cipher_string(token, pad, decipher=False): | |
result = [] | |
for token_char, pad_char in zip(token, pad): | |
token_index = VALID_CHARS.index(token_char) | |
pad_index = VALID_CHARS.index(pad_char) | |
if decipher: | |
result_index = (token_index - pad_index) % len(VALID_CHARS) | |
else: | |
result_index = (token_index + pad_index) % len(VALID_CHARS) | |
result.append(VALID_CHARS[result_index]) | |
return ''.join(result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment