Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 84b18fc

Browse files
Update crypto.py
1 parent 04bacd7 commit 84b18fc

File tree

1 file changed

+108
-63
lines changed

1 file changed

+108
-63
lines changed

‎Cryptography/crypto.py‎

Lines changed: 108 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,107 +1,152 @@
1-
##importing mmodules
2-
3-
from tkinter import *
1+
## importing mmodules
2+
from tkinter import Tk
3+
from tkinter import Label
4+
from tkinter import BOTTOM
5+
from tkinter import StringVar
6+
from tkinter import Entry
7+
from tkinter import Button
48
import base64
59

6-
#initialize window
10+
#initialize window
711
root = Tk()
812
root.geometry('500x300')
9-
root.resizable(0,0)
13+
root.resizable(0,0)
1014

11-
#title of the window
15+
#title of the window
1216
root.title("Cryptography World")
1317

14-
15-
16-
#label
17-
18+
# label
1819
Label(root, text ='ENCODE DECODE', font = 'arial 20 bold').pack()
1920
Label(root, text ='By Anushka Chitranshi', font = 'arial 20 bold').pack(side =BOTTOM)
2021

21-
22-
#define variables
23-
22+
# define variables
2423
Text = StringVar()
2524
private_key = StringVar()
2625
mode = StringVar()
2726
Result = StringVar()
2827

2928

30-
#######define function#####
31-
32-
#function to encode
33-
34-
def Encode(key,message):
35-
enc=[]
36-
for i in range(len(message)):
29+
## define function ##
30+
# function to encode
31+
def Encode(key, message):
32+
'''Takes the key and encode the message'''
33+
enc = []
34+
for i in enumerate(message):
3735
key_c = key[i % len(key)]
3836
enc.append(chr((ord(message[i]) + ord(key_c)) % 256))
3937

4038
return base64.urlsafe_b64encode("".join(enc).encode()).decode()
4139

42-
#function to decode
4340

44-
def Decode(key,message):
45-
dec=[]
41+
# function to decode
42+
def Decode(key, message):
43+
'''Takes the key and decode the message'''
44+
dec = []
4645
message = base64.urlsafe_b64decode(message).decode()
47-
for i in range(len(message)):
46+
for i in enumerate(message):
4847
key_c = key[i % len(key)]
49-
dec.append(chr((256 + ord(message[i])- ord(key_c)) % 256))
48+
dec.append(chr ( (256 + ord(message[i])- ord(key_c ) ) % 256 ) )
5049

5150
return "".join(dec)
5251

53-
#function to set mode
52+
53+
# function to set mode
5454
def Mode():
55-
if(mode.get() == 'e'):
55+
''' Takes the mode of cryptography'''
56+
if mode.get() == 'e':
5657
Result.set(Encode(private_key.get(), Text.get()))
57-
elif(mode.get() == 'd'):
58+
elifmode.get() == 'd':
5859
Result.set(Decode(private_key.get(), Text.get()))
5960
else:
6061
Result.set('Invalid Mode')
6162

62-
63-
64-
#Function to exit window
65-
63+
# Function to exit window
6664
def Exit():
65+
'''Exit the window'''
6766
root.destroy()
6867

69-
70-
#Function to reset
68+
69+
#Function to reset
7170
def Reset():
71+
''' Used to reset the screen'''
7272
Text.set("")
7373
private_key.set("")
7474
mode.set("")
7575
Result.set("")
7676

7777

78-
#################### Label and Button #############
79-
80-
#Message
81-
Label(root, font= 'arial 12 bold', text='MESSAGE').place(x= 60,y=60)
82-
Entry(root, font = 'arial 10', textvariable = Text, bg = 'ghost white').place(x=290, y = 60)
83-
84-
#key
85-
Label(root, font = 'arial 12 bold', text ='KEY').place(x=60, y = 90)
86-
Entry(root, font = 'arial 10', textvariable = private_key , bg ='ghost white').place(x=290, y = 90)
87-
88-
89-
#mode
90-
Label(root, font = 'arial 12 bold', text ='MODE(e-encode, d-decode)').place(x=60, y = 120)
91-
Entry(root, font = 'arial 10', textvariable = mode , bg= 'ghost white').place(x=290, y = 120)
92-
93-
94-
95-
#result
96-
Entry(root, font = 'arial 10 bold', textvariable = Result, bg ='ghost white').place(x=290, y = 150)
97-
98-
######result button
99-
Button(root, font = 'arial 10 bold', text = 'RESULT' ,padx =2,bg ='LightGray' ,command = Mode).place(x=60, y = 150)
100-
101-
102-
#reset button
103-
Button(root, font = 'arial 10 bold' ,text ='RESET' ,width =6, command = Reset,bg = 'LimeGreen', padx=2).place(x=80, y = 190)
104-
105-
#exit button
106-
Button(root, font = 'arial 10 bold',text= 'EXIT' , width = 6, command = Exit,bg = 'OrangeRed', padx=2, pady=2).place(x=180, y = 190)
78+
## Label and Button ##
79+
# Message
80+
Label(
81+
root,
82+
font='arial 12 bold',
83+
text='MESSAGE'
84+
).place(x=60, y=60)
85+
Entry(
86+
root,
87+
font='arial 10',
88+
textvariable=Text,
89+
bg='ghost white'
90+
).place(x=290, y=60)
91+
92+
# key
93+
Label(root, font='arial 12 bold', text='KEY').place(x=60, y=90)
94+
Entry(
95+
root,
96+
font='arial 10',
97+
textvariable=private_key ,
98+
bg='ghost white'
99+
).place(x=290, y=90)
100+
101+
# mode
102+
Label(
103+
root,
104+
font='arial 12 bold',
105+
text='MODE(e-encode, d-decode)'
106+
).place(x=60, y=120)
107+
Entry(
108+
root,
109+
font='arial 10',
110+
textvariable=mode ,
111+
bg='ghost white'
112+
).place(x=290, y =120)
113+
114+
# result
115+
Entry(root,
116+
font='arial 10 bold',
117+
textvariable=Result,
118+
bg='ghost white'
119+
).place(x=290, y=150)
120+
121+
# result button
122+
Button(
123+
root,
124+
font='arial 10 bold',
125+
text='RESULT' ,
126+
padx=2,
127+
bg='LightGray' ,
128+
command=Mode
129+
).place(x=60, y=150)
130+
131+
# reset button
132+
Button(
133+
root,
134+
font='arial 10 bold' ,
135+
text='RESET' ,
136+
width=6,
137+
command=Reset,
138+
bg='LimeGreen',
139+
padx=2
140+
).place(x=80, y=190)
141+
142+
# exit button
143+
Button(
144+
root,
145+
font='arial 10 bold',
146+
text='EXIT' ,
147+
width=6,
148+
command=Exit,
149+
bg='OrangeRed',
150+
padx=2,
151+
pady=2).place(x=180, y=190)
107152
root.mainloop()

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /