Skip to content

Instantly share code, notes, and snippets.

@QuantumFractal
Created December 5, 2016 08:42
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 QuantumFractal/d415a599e50c5438f9d5d8b2728401c6 to your computer and use it in GitHub Desktop.
Save QuantumFractal/d415a599e50c5438f9d5d8b2728401c6 to your computer and use it in GitHub Desktop.
""" 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