Last active
March 3, 2018 09:16
-
-
Save rgov/e128a46e5e8779cb9256 to your computer and use it in GitHub Desktop.
Code to split encipher.it ciphertexts into constituent parts
This file contains hidden or 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 base64 | |
| ct = 'EnCt22bbdc932ace27197eff234c409c2550cc882a4c92bbdc932ace27197eff234c4GMRUZdNqXgHr7zwU7FbknCNZzGy2Z143IJuZ3Q==IwEmS' | |
| ct = ct[5:] # trim 'EnCt2' header | |
| ct = ct[:-5] # trim 'IwEmS' footer | |
| hash = bytes.fromhex(ct[:64]) | |
| hmac = bytes.fromhex(ct[:40]) | |
| assert hash.startswith(hmac) | |
| salt = ct[64:72] | |
| text = base64.b64decode(ct[72:]) | |
| nonce, text = text[:8], text[8:] | |
| def format_cstring(bytes): | |
| return ''.join('\\x' + hex(b)[2:].rjust(2, '0') for b in bytes) | |
| print(' char *salt = \"%s\";' % salt) | |
| print(' uint8_t *hmac = \"%s\";' % format_cstring(hmac)) | |
| print(' uint8_t *nonce = \"%s\";' % format_cstring(nonce)) | |
| print(' uint8_t *ciphertext = \"%s\";' % format_cstring(text)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment