Skip to content

Instantly share code, notes, and snippets.

@brainix
Last active April 14, 2018 19:17
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 brainix/ad92636f6328810ed402fdbb0c4ae7fe to your computer and use it in GitHub Desktop.
Save brainix/ad92636f6328810ed402fdbb0c4ae7fe to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import sys
# Map the uppercase letters forwards:
_MAPPING = {
'Q': 'P',
'W': 'O',
'E': 'I',
'R': 'U',
'T': 'Y',
'A': 'L',
'S': 'K',
'D': 'J',
'F': 'H',
# 'G': 'G',
'Z': 'M',
'X': 'N',
'C': 'B',
# 'V': 'V',
}
# Map the lowercase letters forwards:
_MAPPING.update({key.lower(): value.lower() for key, value in _MAPPING.items()})
# Map both the uppercase and lowercase letters backwards:
_MAPPING.update({value: key for key, value in _MAPPING.items()})
def encrypt(plaintext):
cyphertext = ''.join(_MAPPING.get(c, c) for c in plaintext)
return cyphertext
def main():
plaintext = sys.argv[-1]
cyphertext = encrypt(plaintext)
print(cyphertext)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment