On Sun, 18 Dec 2011 01:11:29 -0800 (PST)
resi147 <[email protected]> wrote:
> Actually I did not get what you meant by "to fix
> it.."
> and how is this related to the number of existing nodes
Just that the process of upgrading the key to unicode would be a pain
for dozens of nodes, but is fine for a few.
The standalone program is attached - I'll push the updated code for
Leo, you'll probably need to upgrade the key in Leo before the
standalone program will work. View the plugin docs. in Leo (select it
from the plugin menu) for details:
If your data doesn't decode, you may need to upgrade your key. Use the
``Alt-X`` ``stickynoterekey`` command on the encryted node in Leo. Prefix
the old key with "v0:" (vee zero colon without the quotes). Enter whatever
you want for the new key, even the old key again without the "v0:".
The decoded data should appear in the popoup window, if not, close the Leo
file **without saving**. If you have multiple encoded nodes, repeat this
process for each one.
Cheers -Terry
--
You received this message because you are subscribed to the Google Groups
"leo-editor" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/leo-editor?hl=en.
"""Encode / decode text with a key the same way the Leo
stickynote(enc) plugin does.
Usage: python snencdec.py infile [outfile]
Encodes if there is at least one space in the input,
otherwise decodes.
"""
import sys
def err(s):
sys.stderr.write(s+'\n')
encOK = False
try:
from Crypto.Cipher import AES
from Crypto.Hash import MD5, SHA
import base64
import textwrap
__ENCKEY = [None]
encOK = True
except ImportError:
pass
if not encOK:
err("Can't find Crypto.Cipher from python-crypto")
exit(10)
def sn_decode(s, key):
return AES.new(key).decrypt(base64.b64decode(s)).strip()
def sn_encode(s, key):
pad = ' '*(16-len(s)%16)
return '\n'.join(textwrap.wrap(
base64.b64encode(AES.new(key).encrypt(s+pad)),
break_long_words = True
))
def sn_getenckey(txt):
# arbitrary kludge to convert string to 256 bits - don't change
txt = unicode(txt)
sha = SHA.new()
md5 = MD5.new()
sha.update(txt)
md5.update(txt)
key = sha.digest()[:16] + md5.digest()[:16]
if len(key) != 32:
err("sn_getenckey failed to build key")
return key
if not 2 <= len(sys.argv) <= 3:
err("Usage: python snencdec.py infile [outfile]")
exit(10)
in_, out = sys.stdin, sys.stdout
in_ = open(sys.argv[1])
if len(sys.argv) == 3:
out = open(sys.argv[2], 'w')
stdout = sys.stdout
sys.stdout = sys.stderr
txt = unicode(raw_input("Enter key: ").strip())
enckey = sn_getenckey(txt)
sys.stdout = stdout
in_dat = in_.read()
if ' ' in in_dat:
out.write(sn_encode(in_dat, enckey)+'\n')
else:
out.write(sn_decode(in_dat, enckey)+'\n')