encode / src /streamlit_app.py
omchaudhari2644's picture
Update src/streamlit_app.py
4e96eae verified
import streamlit as st
import ast
import pyperclip as pyp
class encdec:
def __init__(self, name):
self.name = name
self.enc = name
def encode(self):
enc = [ord(ch) + 7 for ch in self.name]
self.enc = enc
return enc
def decode(self, enc):
return ''.join([chr(val-7) for val in self.enc])
st.title("Text Encoder / Decoder")
choice = st.radio("Select Action:", ("Encode", "Decode"))
if choice == "Encode":
user_input = st.text_input("Enter text to encode:")
if st.button("Encode"):
obj = encdec(user_input)
encoded = obj.encode()
st.success(f"Encoded: {encoded}")
pyp.copy(str(encoded))
elif choice == "Decode":
password = st.text_input("Enter password:", type="password")
if password == "notgood":
user_input = st.text_input("Enter encoded list:")
if st.button("Decode"):
try:
user_input1 = ast.literal_eval(user_input)
obj = encdec(user_input1)
decoded = obj.decode(user_input1)
st.success(f"Decoded: {decoded}")
pyp.copy(decoded)
except:
st.error("Invalid input! Example: [118, 116]")