Skip to content

Commit

Permalink
fix: don’t shit when state is encrypted and new file is added
Browse files Browse the repository at this point in the history
  • Loading branch information
aviaryan committed Feb 22, 2017
1 parent e515994 commit f167fb7
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions cryptlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,25 @@
import os

EXTRA_STR = 'ENCo0D#DT{xTCh$cKe>'
ENCODED_IDF = '=*=EnC0d3dH3aDer==*'


def encode(key, clear):
st = ''
clear += EXTRA_STR
if clear.startswith(ENCODED_IDF): # already encoded, no need to encode
return clear
clear += EXTRA_STR # used to check if decrypt is correct
incr = get_key_hash(key)
for _ in clear:
st += chr(incr + ord(_))
return base64.b64encode(st.encode('utf-8')).decode('utf-8')
return ENCODED_IDF + base64.b64encode(st.encode('utf-8')).decode('utf-8')


def decode(key, enc):
st = ''
if not enc.startswith(ENCODED_IDF): # not encoded, so not decode
return enc
enc = enc[len(ENCODED_IDF):] # trim out idf
enc = base64.b64decode(enc).decode('utf-8') # dont know why urlsafe decode doesn't work
incr = get_key_hash(key)
for _ in enc:
Expand Down

0 comments on commit f167fb7

Please sign in to comment.