-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
91 lines (68 loc) · 2.33 KB
/
app.py
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import streamlit as st
import numpy as np
import func as obj
st.title("Mysterion")
st.sidebar.title("Mysterion")
st.markdown("Mysterion Block Cipher Encrypt-Decrypt Tool")
st.sidebar.markdown("Mysterion Block Cipher Encrypt-Decrypt Tool")
inpt = "01010000B2C3D4E5F60718293A4B5C6D"
key = "0205060752F3E1F2132435465B6C7D88"
inpt = st.sidebar.text_input("Plaintext in hexadecimal", inpt)
key = st.sidebar.text_input("Key in hexadecimal", key)
NR = st.sidebar.slider("Rounds", 1, 16, 12, 1)
opt = st.sidebar.radio('Operation', ('Encrypt', 'Decrypt', 'Both'))
def encrypt(m, k):
m = list(bytearray.fromhex(m))
k = list(bytearray.fromhex(k))
# spliting message in blocks
m = np.array([m[i*4:(i+1)*4] for i in range(4)])
k = np.array([k[i*4:(i+1)*4] for i in range(4)])
ct = obj.Mysterion128(k, m, NR)
h_ct = ""
for i in ct:
h_ct += ''.join('{:02x}'.format(x) for x in i)
return h_ct
def decrypt(m, k):
m = list(bytearray.fromhex(m))
k = list(bytearray.fromhex(k))
# spliting message in blocks
m = np.array([m[i*4:(i+1)*4] for i in range(4)])
k = np.array([k[i*4:(i+1)*4] for i in range(4)])
cpt = obj.InvMysterion128(m, k, NR)
h_cpt = ""
for i in cpt:
h_cpt += ''.join('{:02x}'.format(x) for x in i)
return h_cpt
def endecrypt(m, k):
m = list(bytearray.fromhex(m))
k = list(bytearray.fromhex(k))
# spliting message in blocks
m = np.array([m[i*4:(i+1)*4] for i in range(4)])
k = np.array([k[i*4:(i+1)*4] for i in range(4)])
ct = obj.Mysterion128(k, m, NR)
cpt = obj.InvMysterion128(ct, k, NR)
h_ct = ""
for i in ct:
h_ct += ''.join('{:02x}'.format(x) for x in i)
h_cpt = ""
for i in cpt:
h_cpt += ''.join('{:02x}'.format(x) for x in i)
return (h_ct, h_cpt)
if opt == "Encrypt":
ct = encrypt(inpt, key)
st.text("Encryption")
st.text("Plaintext : " + inpt)
st.text("Ciphertext : " + ct)
elif opt == "Decrypt":
cpt = decrypt(inpt, key)
st.text("Decryption")
st.text("Ciphertext : " + inpt)
st.text("Computed Plaintext : " + cpt)
else:
ct, cpt = endecrypt(inpt, key)
st.text("Encryption")
st.text("Plaintext : " + inpt)
st.text("Ciphertext : " + ct)
st.text("Decryption")
st.text("Ciphertext : " + ct)
st.text("Computed Plaintext : " + cpt)