Skip to content

Instantly share code, notes, and snippets.

@effective-light
Last active June 19, 2017 21:08
Show Gist options
  • Save effective-light/64a9af009cdc8b5df253b6dc94574157 to your computer and use it in GitHub Desktop.
Save effective-light/64a9af009cdc8b5df253b6dc94574157 to your computer and use it in GitHub Desktop.
def bob_cipher(phrase: str, key: str) -> str:
"""
>>> bob_cipher("ANT", "BOB")
B25O25B18
"""
new_s = ""
for key_char, phrase_char in zip(key, phrase):
key_ord = ord(key_char)
phrase_ord = ord(phrase_char)
if key_ord <= phrase_ord:
new_s += phrase_char + str(phrase_ord - key_ord)
else:
new_s += key_char + str(25)
return new_s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment