parent
170cafc10f
commit
13d488f440
10
aes.py
10
aes.py
|
@ -4,6 +4,7 @@
|
||||||
import os, popen2
|
import os, popen2
|
||||||
|
|
||||||
class Cipher:
|
class Cipher:
|
||||||
|
'''Cipher represents a particular hashing strategy (password, seed, and type). Cipher can encrypt or decrypt data.'''
|
||||||
def __init__(self, password, seed='aes.py', hashtype='rmd160'):
|
def __init__(self, password, seed='aes.py', hashtype='rmd160'):
|
||||||
self.password = password
|
self.password = password
|
||||||
self.seed = seed
|
self.seed = seed
|
||||||
|
@ -14,12 +15,13 @@ class Cipher:
|
||||||
return decrypt_data(encrypted, self.password, self.seed, self.hashtype)
|
return decrypt_data(encrypted, self.password, self.seed, self.hashtype)
|
||||||
|
|
||||||
def _check_aespipe():
|
def _check_aespipe():
|
||||||
|
'''This function checks if we have the "aespipe" binary in $PATH'''
|
||||||
result = os.system('which aespipe > /dev/null')
|
result = os.system('which aespipe > /dev/null')
|
||||||
if result != 0:
|
if result != 0:
|
||||||
raise Exception, "Could not find aespipe; is it installed?"
|
raise Exception, "Could not find aespipe; is it installed?"
|
||||||
|
|
||||||
def encrypt_data(data, password, seed='aes.py', hashtype='rmd160'):
|
def encrypt_data(data, password, seed='aes.py', hashtype='rmd160'):
|
||||||
'''uses password to encrypt data'''
|
'''Uses password to encrypt data'''
|
||||||
_check_aespipe()
|
_check_aespipe()
|
||||||
cmd = "aespipe -S '%s' -H '%s' -p 0" % (seed, hashtype)
|
cmd = "aespipe -S '%s' -H '%s' -p 0" % (seed, hashtype)
|
||||||
(stdout, stdin, stderr) = popen2.popen3(cmd)
|
(stdout, stdin, stderr) = popen2.popen3(cmd)
|
||||||
|
@ -33,14 +35,14 @@ def encrypt_data(data, password, seed='aes.py', hashtype='rmd160'):
|
||||||
return encrypted
|
return encrypted
|
||||||
|
|
||||||
def encrypt_path(path, data, password, seed='aes.py', hashtype='rmd160'):
|
def encrypt_path(path, data, password, seed='aes.py', hashtype='rmd160'):
|
||||||
'''uses password to encrypt data and writes result to path'''
|
'''Uses password to encrypt data and writes result to path'''
|
||||||
encrypted = encrypt_data(data, password, seed, hashtype)
|
encrypted = encrypt_data(data, password, seed, hashtype)
|
||||||
f = open(path, 'w')
|
f = open(path, 'w')
|
||||||
f.write(encrypted)
|
f.write(encrypted)
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
def decrypt_data(encrypted, password, seed='aes.py', hashtype='rmd160'):
|
def decrypt_data(encrypted, password, seed='aes.py', hashtype='rmd160'):
|
||||||
'''uses password to decrypt data'''
|
'''Uses password to decrypt data'''
|
||||||
_check_aespipe()
|
_check_aespipe()
|
||||||
cmd = "aespipe -d -S '%s' -H '%s' -p 0" % (seed, hashtype)
|
cmd = "aespipe -d -S '%s' -H '%s' -p 0" % (seed, hashtype)
|
||||||
(stdout, stdin, stderr) = popen2.popen3(cmd)
|
(stdout, stdin, stderr) = popen2.popen3(cmd)
|
||||||
|
@ -62,7 +64,7 @@ def decrypt_data(encrypted, password, seed='aes.py', hashtype='rmd160'):
|
||||||
return data[:i]
|
return data[:i]
|
||||||
|
|
||||||
def decrypt_path(path, password, seed='aes.py', hashtype='rmd160'):
|
def decrypt_path(path, password, seed='aes.py', hashtype='rmd160'):
|
||||||
'''uses password to decrypt data from path'''
|
'''Uses password to decrypt data from path'''
|
||||||
f = open(path, 'r')
|
f = open(path, 'r')
|
||||||
encrypted = f.read()
|
encrypted = f.read()
|
||||||
f.close()
|
f.close()
|
||||||
|
|
|
@ -3,9 +3,9 @@ import aes, dirutil, regex, highlight
|
||||||
from point import Point
|
from point import Point
|
||||||
|
|
||||||
# undo/redo stack constants
|
# undo/redo stack constants
|
||||||
ACT_NORM = 0
|
ACT_NORM = 0
|
||||||
ACT_UNDO = 1
|
ACT_UNDO = 1
|
||||||
ACT_REDO = 2
|
ACT_REDO = 2
|
||||||
STACK_LIMIT = 1024
|
STACK_LIMIT = 1024
|
||||||
|
|
||||||
# used for undo/redo stacks when text will need to be added back
|
# used for undo/redo stacks when text will need to be added back
|
||||||
|
|
Loading…
Reference in New Issue