mirror of
https://github.com/metafy-social/python-scripts.git
synced 2024-11-23 20:11:10 +00:00
Added message encoder-decoder
Tech stack py
This commit is contained in:
parent
6a96ef559f
commit
d3d4946212
20
scripts/Message Encoder and Decoder/README.md
Normal file
20
scripts/Message Encoder and Decoder/README.md
Normal file
|
@ -0,0 +1,20 @@
|
|||
# Message Encoder and Decoder
|
||||
|
||||
A web application used to encrypt and decrypt text messages.
|
||||
- For the encodings listed in RFC 4648, it offers encoding and decoding functions.
|
||||
|
||||
## Tech Stack 🛠
|
||||
![Python](https://img.shields.io/badge/Python-3.9-yellowgreen)
|
||||
![Streamlit](https://img.shields.io/badge/Streamlit-0.85.1-red)
|
||||
![base64](https://img.shields.io/badge/-base64-lightgrey)
|
||||
|
||||
## Features ⚡
|
||||
|
||||
- Encoding and Decoding using Private Key
|
||||
- Neat and Clean UI
|
||||
|
||||
## Demo 👀
|
||||
|
||||
[streamlit-app-encode-decode.webm](https://user-images.githubusercontent.com/81156510/183291295-e759eb45-0c1c-4d4e-9f5a-e2f3f95f8a72.webm)
|
||||
|
||||
<hr>
|
45
scripts/Message Encoder and Decoder/app.py
Normal file
45
scripts/Message Encoder and Decoder/app.py
Normal file
|
@ -0,0 +1,45 @@
|
|||
import streamlit as st
|
||||
import base64
|
||||
|
||||
# Function to Encode
|
||||
|
||||
def Encode(key, message):
|
||||
enc=[]
|
||||
for i in range(len(message)):
|
||||
key_c = key[i % len(key)]
|
||||
enc.append(chr((ord(message[i]) + ord(key_c)) % 256))
|
||||
|
||||
return base64.urlsafe_b64encode("".join(enc).encode()).decode()
|
||||
|
||||
|
||||
# Function to decode
|
||||
|
||||
def Decode(key, message):
|
||||
dec=[]
|
||||
message = base64.urlsafe_b64decode(message).decode()
|
||||
for i in range(len(message)):
|
||||
key_c = key[i % len(key)]
|
||||
dec.append(chr((256 + ord(message[i])- ord(key_c)) % 256))
|
||||
|
||||
return "".join(dec)
|
||||
|
||||
message = st.text_input('Message Text')
|
||||
|
||||
key = st.text_input(
|
||||
"Private key", type="password"
|
||||
)
|
||||
|
||||
mode = st.selectbox(
|
||||
"What action would you like to perform?",
|
||||
("Encode", "Decode")
|
||||
)
|
||||
|
||||
if st.button('Result'):
|
||||
if (mode == "Encode"):
|
||||
# Encode(key, message)
|
||||
st.write(Encode(key, message))
|
||||
else:
|
||||
st.write(Decode(key, message))
|
||||
else:
|
||||
st.write('Please enter all the required information!!')
|
||||
|
Loading…
Reference in New Issue
Block a user