#!/usr/bin/python

import sys
import base64
from pyDes import *

saltFn = "%(configFolder)s/salt"
f = open(saltFn)
salt_property = f.read()
f.close()

key = salt_property.split("=")[1].strip()

def obscure(data=""):
    engine = triple_des(key, ECB, pad=None, padmode=PAD_PKCS5)
    data = data.encode('ascii')
    en_data = engine.encrypt(data)
    return base64.b64encode(en_data)

def unobscure(s=""):
    engine = triple_des(key, ECB, pad=None, padmode=PAD_PKCS5)
    cipher = triple_des(key)
    decrypted = cipher.decrypt(base64.b64decode(s), padmode=PAD_PKCS5)
    return decrypted

def Usage():
    print "To encode:   encode <string>"
    print "To decode:   encode -D <string>"
    print
    sys.exit(0)

arg = ""
decode = False
if len(sys.argv) == 1:
    Usage()
if len(sys.argv) == 3:
    decode = True
    arg = sys.argv[2]
if len(sys.argv) == 2:
    arg = sys.argv[1]

if decode:
    print unobscure(arg)
else:
    print obscure(arg)
@@ -10,16 +10,17 @@
 n/python
+3
 %0A%0Aimport
@@ -376,16 +376,32 @@
 en_data)
+.decode('utf-8')
 %0A%0Adef un
@@ -598,16 +598,32 @@
 ecrypted
+.decode('utf-8')
 %0A%0Adef Us
@@ -634,25 +634,25 @@
 ):%0A    print
- 
+(
 %22To encode: 
@@ -661,32 +661,33 @@
 encode %3Cstring%3E%22
+)
 %0A    print %22To d
@@ -680,17 +680,17 @@
    print
- 
+(
 %22To deco
@@ -714,16 +714,17 @@
 string%3E%22
+)
 %0A    pri
@@ -725,16 +725,18 @@
    print
+()
 %0A    sys
@@ -933,17 +933,17 @@
    print
- 
+(
 unobscur
@@ -948,16 +948,17 @@
 ure(arg)
+)
 %0Aelse:%0A 
@@ -965,17 +965,17 @@
    print
- 
+(
 obscure(
@@ -966,20 +966,22 @@
   print(obscure(arg)
+)%0A

migrate encode.py to py3