Created
January 28, 2015 06:49
-
-
Save badmofo/abab1d7a3d4d3e1a9ec3 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
import scrypt | |
import sys | |
from itertools import count | |
from nacl.secret import SecretBox | |
from nacl.utils import random | |
from nacl.exceptions import CryptoError | |
def kdf(password): | |
N = 16384 | |
r = 1024 | |
p = 1 | |
return scrypt.hash(password, 'timelock', N, r, p, SecretBox.KEY_SIZE) | |
if sys.argv[1] == 'e': | |
minutes = int(float(sys.argv[2]) * 8.0) | |
key = sys.argv[3] | |
for i in xrange(minutes): | |
key = kdf(key) | |
nonce = random(SecretBox.NONCE_SIZE) | |
message = sys.argv[4] | |
box = SecretBox(key) | |
encrypted = box.encrypt(message, nonce) | |
print encrypted.encode('base64').replace('\n', '') | |
elif sys.argv[1] == 'd': | |
key = sys.argv[2] | |
ciphertext = sys.argv[3].decode('base64') | |
for i in count(): | |
key = kdf(key) | |
print 'trying', i | |
box = SecretBox(key) | |
try: | |
print box.decrypt(ciphertext) | |
break | |
except CryptoError, e: | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment