summaryrefslogtreecommitdiffstats
path: root/pykolab/utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'pykolab/utils.py')
-rw-r--r--pykolab/utils.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/pykolab/utils.py b/pykolab/utils.py
index 5cba8f9..b7ff468 100644
--- a/pykolab/utils.py
+++ b/pykolab/utils.py
@@ -17,6 +17,7 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
+import base64
import getpass
import grp
import os
@@ -182,6 +183,29 @@ def ask_menu(question, options={}, default=''):
return answer
+def decode(key, enc):
+ if key == None:
+ return enc
+
+ dec = []
+ enc = base64.urlsafe_b64decode(enc)
+ for i in range(len(enc)):
+ key_c = key[i % len(key)]
+ dec_c = chr((256 + ord(enc[i]) - ord(key_c)) % 256)
+ dec.append(dec_c)
+ return "".join(dec)
+
+def encode(key, clear):
+ if key == None:
+ return clear
+
+ enc = []
+ for i in range(len(clear)):
+ key_c = key[i % len(key)]
+ enc_c = chr((ord(clear[i]) + ord(key_c)) % 256)
+ enc.append(enc_c)
+ return base64.urlsafe_b64encode("".join(enc))
+
def ensure_directory(_dir, _user='root', _group='root'):
if not os.path.isdir(_dir):
os.makedirs(_dir)