Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +15 -31
src/streamlit_app.py
CHANGED
|
@@ -1,4 +1,3 @@
|
|
| 1 |
-
# save this file as app.py
|
| 2 |
import streamlit as st
|
| 3 |
import ast
|
| 4 |
import pyperclip as pyp
|
|
@@ -7,23 +6,13 @@ class encdec:
|
|
| 7 |
def __init__(self, name):
|
| 8 |
self.name = name
|
| 9 |
self.enc = name
|
| 10 |
-
|
| 11 |
def encode(self):
|
| 12 |
-
enc = []
|
| 13 |
-
new_name = list(self.name)
|
| 14 |
-
for ch in new_name:
|
| 15 |
-
enc.append(ord(ch) + 7)
|
| 16 |
self.enc = enc
|
| 17 |
return enc
|
| 18 |
-
|
| 19 |
def decode(self, enc):
|
| 20 |
-
|
| 21 |
-
for ch1 in self.enc:
|
| 22 |
-
val = ch1
|
| 23 |
-
dec.append(chr(val - 7))
|
| 24 |
-
return ''.join(dec)
|
| 25 |
|
| 26 |
-
# Streamlit UI
|
| 27 |
st.title("Text Encoder / Decoder")
|
| 28 |
|
| 29 |
choice = st.radio("Select Action:", ("Encode", "Decode"))
|
|
@@ -34,23 +23,18 @@ if choice == "Encode":
|
|
| 34 |
obj = encdec(user_input)
|
| 35 |
encoded = obj.encode()
|
| 36 |
st.success(f"Encoded: {encoded}")
|
| 37 |
-
pyp.copy(str(encoded))
|
| 38 |
-
st.info("Encoded value copied to clipboard!")
|
| 39 |
|
| 40 |
elif choice == "Decode":
|
| 41 |
-
password = st.text_input("Enter password
|
| 42 |
-
if password:
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
except:
|
| 54 |
-
st.error("Invalid input! Enter a valid list like [118, 116].")
|
| 55 |
-
else:
|
| 56 |
-
st.error("Incorrect password! Access denied.")
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import ast
|
| 3 |
import pyperclip as pyp
|
|
|
|
| 6 |
def __init__(self, name):
|
| 7 |
self.name = name
|
| 8 |
self.enc = name
|
|
|
|
| 9 |
def encode(self):
|
| 10 |
+
enc = [ord(ch) + 7 for ch in self.name]
|
|
|
|
|
|
|
|
|
|
| 11 |
self.enc = enc
|
| 12 |
return enc
|
|
|
|
| 13 |
def decode(self, enc):
|
| 14 |
+
return ''.join([chr(val-7) for val in self.enc])
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
|
|
|
| 16 |
st.title("Text Encoder / Decoder")
|
| 17 |
|
| 18 |
choice = st.radio("Select Action:", ("Encode", "Decode"))
|
|
|
|
| 23 |
obj = encdec(user_input)
|
| 24 |
encoded = obj.encode()
|
| 25 |
st.success(f"Encoded: {encoded}")
|
| 26 |
+
pyp.copy(str(encoded))
|
|
|
|
| 27 |
|
| 28 |
elif choice == "Decode":
|
| 29 |
+
password = st.text_input("Enter password:", type="password")
|
| 30 |
+
if password == "notgood":
|
| 31 |
+
user_input = st.text_input("Enter encoded list:")
|
| 32 |
+
if st.button("Decode"):
|
| 33 |
+
try:
|
| 34 |
+
user_input1 = ast.literal_eval(user_input)
|
| 35 |
+
obj = encdec(user_input1)
|
| 36 |
+
decoded = obj.decode(user_input1)
|
| 37 |
+
st.success(f"Decoded: {decoded}")
|
| 38 |
+
pyp.copy(decoded)
|
| 39 |
+
except:
|
| 40 |
+
st.error("Invalid input! Example: [118, 116]")
|
|
|
|
|
|
|
|
|
|
|
|