Last active
April 14, 2018 19:17
-
-
Save brainix/ad92636f6328810ed402fdbb0c4ae7fe to your computer and use it in GitHub Desktop.
Encrypt a message: https://www.reddit.com/r/learnpython/comments/8c56aq/i_want_to_create_a_simple_program_for_my_brother/
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
#!/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