-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathencrypt.py
More file actions
32 lines (22 loc) · 867 Bytes
/
encrypt.py
File metadata and controls
32 lines (22 loc) · 867 Bytes
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
# ==============================================================================
#
# Use:
# encrypt("Hello World!", "key")
# => b'WzM3NDQyLCA1MjQ4OCwgNTU4NzQsIDU2MDcyLCA1NzQxMCwgMTcxNjAsIDQ1MTIyLCA1NzYwOCwgNTg5NDYsIDU2MDcyLCA1MTc3OCwgMTc2NzJd'
#
# ==============================================================================
import base64
def encode(text):
encoded_arr = [ord(i) for i in text]
return encoded_arr
def encrypt(text, key):
encoded_text = encode(text)
encoded_key = encode(key)
buf = []
for x in encoded_text:
for i in encoded_key:
x = x + 1 << i % 8
encoded_key = list(reversed(encoded_key))
buf.append(x)
encrypt_string = base64.b64encode(str(buf).encode("ascii"))
return encrypt_string