File size: 1,234 Bytes
eb71593
6278eca
 
 
 
 
 
 
 
4e96eae
6278eca
 
 
4e96eae
6278eca
 
 
 
 
 
 
 
 
 
 
4e96eae
6278eca
 
4e96eae
 
 
 
 
 
 
 
 
 
 
 
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
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]")