Skip to content

Instantly share code, notes, and snippets.

@rgov
Last active March 3, 2018 09:16
Show Gist options
  • Select an option

  • Save rgov/e128a46e5e8779cb9256 to your computer and use it in GitHub Desktop.

Select an option

Save rgov/e128a46e5e8779cb9256 to your computer and use it in GitHub Desktop.
Code to split encipher.it ciphertexts into constituent parts
#!/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