File size: 1,850 Bytes
d2c4332
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
46
47
48
49
50
51
52
53
54
55
56
57
# save this file as app.py
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 = []
        new_name = list(self.name)
        for ch in new_name:
            enc.append(ord(ch) + 7)
        self.enc = enc
        return enc

    def decode(self, enc):
        dec = []
        for ch1 in self.enc:
            val = ch1
            dec.append(chr(val - 7))
        return ''.join(dec)

# Streamlit UI
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))  # copy encoded list to clipboard
        st.info("Encoded value copied to clipboard!")

elif choice == "Decode":
    password = st.text_input("Enter password for decoding:", type="password")
    if password:
        if password == "notgood":
            user_input = st.text_input("Enter text to decode (e.g., [118, 116]):")
            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)  # copy decoded text to clipboard
                    st.info("Decoded value copied to clipboard!")
                except:
                    st.error("Invalid input! Enter a valid list like [118, 116].")
        else:
            st.error("Incorrect password! Access denied.")