Created
December 5, 2016 08:42
-
-
Save QuantumFractal/d415a599e50c5438f9d5d8b2728401c6 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
""" Scratch file for Crypto.io """ | |
plaintext_space = "0123456789ABCDEF" | |
key = {'0': 'F', '1': '2', '2': '7', '3': '4', | |
'4': '5', '5': 'C', '6': '9', '7': 'E', | |
'8': 'D', '9': '1', 'A': '3', 'B': '6', | |
'C': '3', 'D': 'A', 'E': 'B', 'F': '0'} | |
def main(): | |
plaintext = "12B70ADE" | |
cryptotext = encrypt(key, plaintext) | |
othertext = decrypt(key, cryptotext) | |
print(othertext) | |
def encrypt(k, P): | |
return ''.join([key[p] for p in P]) | |
def decrypt(k, C): | |
reverse_key = {k[val]: val for val in k} | |
return ''.join(reverse_key[c] for c in C) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment