summaryrefslogtreecommitdiff
path: root/sbhs_server/helpers/simple_encrypt.py
diff options
context:
space:
mode:
authorttt2017-05-13 00:29:47 +0530
committerttt2017-05-13 00:29:47 +0530
commitabf599be33b383a6a5baf9493093b2126a622ac8 (patch)
tree4c5ab6e0d935d5e65fabcf0258e4a00dd20a5afa /sbhs_server/helpers/simple_encrypt.py
downloadSBHS-2018-Rpi-abf599be33b383a6a5baf9493093b2126a622ac8.tar.gz
SBHS-2018-Rpi-abf599be33b383a6a5baf9493093b2126a622ac8.tar.bz2
SBHS-2018-Rpi-abf599be33b383a6a5baf9493093b2126a622ac8.zip
added all server files
Diffstat (limited to 'sbhs_server/helpers/simple_encrypt.py')
-rw-r--r--sbhs_server/helpers/simple_encrypt.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/sbhs_server/helpers/simple_encrypt.py b/sbhs_server/helpers/simple_encrypt.py
new file mode 100644
index 0000000..976fe4d
--- /dev/null
+++ b/sbhs_server/helpers/simple_encrypt.py
@@ -0,0 +1,34 @@
+import base64
+
+def encrypt(cleartext):
+ string = cleartext
+
+ string = string[::-1]
+
+ for i in xrange(3):
+ string = base64.b32encode(string)
+ string = string[::-1]
+ string = string.lower()
+
+ padding = string.count("=")
+ string = string.replace("=", "")
+ return str(padding) + "." + string
+
+
+
+def decrypt(ciphertext):
+ data = ciphertext.split(".")
+ padding = int(data[0])
+ cipher = data[1]
+
+ for i in xrange(padding):
+ cipher = "=" + cipher
+
+ string = cipher
+
+ for i in xrange(3):
+ string = string.upper()
+ string = string[::-1]
+ string = base64.b32decode(string)
+
+ return string[::-1] \ No newline at end of file