forked from metafy-social/python-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
45 lines (33 loc) · 1.04 KB
/
Copy pathapp.py
File metadata and controls
45 lines (33 loc) · 1.04 KB
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
35
36
37
38
39
40
41
42
43
44
45
import streamlit as st
import base64
# Function to Encode
def Encode(key, message):
enc=[]
for i in range(len(message)):
key_c = key[i % len(key)]
enc.append(chr((ord(message[i]) + ord(key_c)) % 256))
return base64.urlsafe_b64encode("".join(enc).encode()).decode()
# Function to decode
def Decode(key, message):
dec=[]
message = base64.urlsafe_b64decode(message).decode()
for i in range(len(message)):
key_c = key[i % len(key)]
dec.append(chr((256 + ord(message[i])- ord(key_c)) % 256))
return "".join(dec)
message = st.text_input('Message Text')
key = st.text_input(
"Private key", type="password"
)
mode = st.selectbox(
"What action would you like to perform?",
("Encode", "Decode")
)
if st.button('Result'):
if (mode == "Encode"):
# Encode(key, message)
st.write(Encode(key, message))
else:
st.write(Decode(key, message))
else:
st.write('Please enter all the required information!!')