Spaces:
Sleeping
Sleeping
Upload encapp.py
Browse files
encapp.py
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# save this file as app.py
|
| 2 |
+
import streamlit as st
|
| 3 |
+
import ast
|
| 4 |
+
import pyperclip as pyp
|
| 5 |
+
|
| 6 |
+
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 |
+
dec = []
|
| 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"))
|
| 30 |
+
|
| 31 |
+
if choice == "Encode":
|
| 32 |
+
user_input = st.text_input("Enter text to encode:")
|
| 33 |
+
if st.button("Encode"):
|
| 34 |
+
obj = encdec(user_input)
|
| 35 |
+
encoded = obj.encode()
|
| 36 |
+
st.success(f"Encoded: {encoded}")
|
| 37 |
+
pyp.copy(str(encoded)) # copy encoded list to clipboard
|
| 38 |
+
st.info("Encoded value copied to clipboard!")
|
| 39 |
+
|
| 40 |
+
elif choice == "Decode":
|
| 41 |
+
password = st.text_input("Enter password for decoding:", type="password")
|
| 42 |
+
if password:
|
| 43 |
+
if password == "notgood":
|
| 44 |
+
user_input = st.text_input("Enter text to decode (e.g., [118, 116]):")
|
| 45 |
+
if st.button("Decode"):
|
| 46 |
+
try:
|
| 47 |
+
user_input1 = ast.literal_eval(user_input)
|
| 48 |
+
obj = encdec(user_input1)
|
| 49 |
+
decoded = obj.decode(user_input1)
|
| 50 |
+
st.success(f"Decoded: {decoded}")
|
| 51 |
+
pyp.copy(decoded) # copy decoded text to clipboard
|
| 52 |
+
st.info("Decoded value copied to clipboard!")
|
| 53 |
+
except:
|
| 54 |
+
st.error("Invalid input! Enter a valid list like [118, 116].")
|
| 55 |
+
else:
|
| 56 |
+
st.error("Incorrect password! Access denied.")
|