diff --git a/jrnl/Journal.py b/jrnl/Journal.py index 4fdffa14..bd1eab52 100644 --- a/jrnl/Journal.py +++ b/jrnl/Journal.py @@ -67,7 +67,7 @@ class Journal(object): util.prompt("ERROR: Your journal file seems to be corrupted. You do have a backup, don't you?") sys.exit(1) - padding_length = ord(plain[-1]) + padding_length = util.byte2int(plain[-1]) if padding_length > AES.block_size and padding_length != 32: # 32 is the space character and is kept for backwards compatibility return None diff --git a/jrnl/util.py b/jrnl/util.py index 3a92f0e4..315666b3 100644 --- a/jrnl/util.py +++ b/jrnl/util.py @@ -145,3 +145,10 @@ def int2byte(i): """Converts an integer to a byte. This is equivalent to chr() in Python 2 and bytes((i,)) in Python 3.""" return chr(i) if PY2 else bytes((i,)) + + +def byte2int(b): + """Converts a byte to an integer. + This is equivalent to ord(bs[0]) on Python 2 and bs[0] on Python 3.""" + return ord(b)if PY2 else b +