Last active
December 20, 2019 12:10
-
-
Save zettelmuseum/eba76cdf702ec12cb0fb7307d149a5d9 to your computer and use it in GitHub Desktop.
Decrypting Epsilon Note encoded notes with python - updated for aes256 and python3 (first do: pip install pycrypto)
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/python | |
###################################################################### | |
# Decrypt an Epsilon Note encoded file given the password. | |
# | |
# This file is in the public domain. | |
# | |
# original file by Dov Grobgeld <[email protected]> 2017-02-17 | |
# | |
# adapted to python3 and aes256 by [email protected] 2019-12-17 | |
# first do: | |
# pip install pycrypto | |
# | |
###################################################################### | |
import sys,io,base64,hashlib | |
from Crypto.Cipher import AES | |
def unpad(s): | |
return s[0:-ord(s[-1:])] | |
def filetob64(handle): | |
b64 = '' | |
within = False | |
for line in handle: | |
if '~~~~~~~~~~' in line: | |
within = not within | |
continue | |
if within: | |
b64 += line[:-1] | |
return b64 | |
def en_decrypt(handle, password): | |
raw = base64.b64decode(filetob64(handle)) | |
enc_text,iv = raw[:-16],raw[-16:] | |
key = hashlib.sha256(password.encode('utf-8')).digest() | |
aes = AES.new(key, AES.MODE_CBC, iv) | |
return unpad(aes.decrypt(enc_text)) | |
if len(sys.argv) > 1: | |
handle = open(sys.argv[1]) | |
password = sys.argv[2] | |
else: | |
# test below | |
encrypted_text = ''' | |
~~~~~~~~~~encrypted | |
hT0pu7ME4NA6L2XQmmsksgiEQaga7sYXzHDJRWMx1NWiKO1IO0OCkhLl5K/LozwvoC35hYJv8SqJLoAizOlD1imq8zxLZI5O3ww+ySYk2SA= | |
~~~~~~~~~~ | |
''' | |
password = 'password' | |
handle = io.StringIO(encrypted_text) | |
print(en_decrypt(handle, password)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
for bash one-liner to do the same, see
https://gist.github.com/zettelding/4f4eea0941ef94a83c0b75caab75a722