summaryrefslogtreecommitdiff
path: root/sbhs_server/helpers/simple_encrypt.py
blob: 976fe4dad9c17d15fdbc307dd376ec08324b6a3a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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]