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 351fe5c

Browse files
Update crypto.py
1 parent 84b18fc commit 351fe5c

File tree

1 file changed

+22
-60
lines changed

1 file changed

+22
-60
lines changed

‎Cryptography/crypto.py‎

Lines changed: 22 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
## importing mmodules
21
from tkinter import Tk
32
from tkinter import Label
43
from tkinter import BOTTOM
@@ -16,8 +15,8 @@
1615
root.title("Cryptography World")
1716

1817
# label
19-
Label(root, text='ENCODE DECODE', font='arial 20 bold').pack()
20-
Label(root, text='By Anushka Chitranshi', font='arial 20 bold').pack(side=BOTTOM)
18+
Label(root, text='ENCODE DECODE', font='arial 20 bold').pack()
19+
Label(root, text='By Anushka Chitranshi', font='arial 20 bold').pack(side=BOTTOM)
2120

2221
# define variables
2322
Text = StringVar()
@@ -26,127 +25,90 @@
2625
Result = StringVar()
2726

2827

29-
## define function ##
3028
# function to encode
3129
def Encode(key, message):
32-
'''Takes the key and encode the message'''
30+
"""Encode the message."""
3331
enc = []
3432
for i in enumerate(message):
3533
key_c = key[i % len(key)]
3634
enc.append(chr((ord(message[i]) + ord(key_c)) % 256))
37-
3835
return base64.urlsafe_b64encode("".join(enc).encode()).decode()
3936

4037

4138
# function to decode
4239
def Decode(key, message):
43-
'''Takes the key and decode the message'''
40+
"""Decode the message."""
4441
dec = []
4542
message = base64.urlsafe_b64decode(message).decode()
4643
for i in enumerate(message):
4744
key_c = key[i % len(key)]
48-
dec.append (chr ( (256 + ord( message[i] )- ord( key_c ) ) % 256 ) )
49-
45+
dec.append(chr((256 + ord(message[i]) - ord(key_c)) % 256))
5046
return "".join(dec)
5147

5248

5349
# function to set mode
5450
def Mode():
55-
''' Takes the mode of cryptography'''
51+
"""Take mode of cryptography."""
5652
if mode.get() == 'e':
5753
Result.set(Encode(private_key.get(), Text.get()))
5854
elif mode.get() == 'd':
5955
Result.set(Decode(private_key.get(), Text.get()))
6056
else:
6157
Result.set('Invalid Mode')
6258

63-
# Function to exit window
59+
# Function to exit window
6460
def Exit():
65-
'''Exit the window'''
61+
"""Exit the window."""
6662
root.destroy()
6763

68-
6964
# Function to reset
7065
def Reset():
71-
''' Used to reset the screen'''
66+
"""Reset the screen."""
7267
Text.set("")
7368
private_key.set("")
7469
mode.set("")
7570
Result.set("")
7671

77-
78-
## Label and Button ##
72+
7973
# Message
8074
Label(
81-
root,
82-
font='arial 12 bold',
83-
text='MESSAGE'
75+
root, font='arial 12 bold', text='MESSAGE'
8476
).place(x=60, y=60)
8577
Entry(
86-
root,
87-
font='arial 10',
88-
textvariable=Text,
89-
bg='ghost white'
78+
root, font='arial 10', textvariable=Text, bg='ghost white'
9079
).place(x=290, y=60)
9180

9281
# key
9382
Label(root, font='arial 12 bold', text='KEY').place(x=60, y=90)
9483
Entry(
95-
root,
96-
font='arial 10',
97-
textvariable=private_key ,
98-
bg='ghost white'
84+
root, font='arial 10', textvariable=private_key , bg='ghost white'
9985
).place(x=290, y=90)
10086

10187
# mode
10288
Label(
103-
root,
104-
font='arial 12 bold',
105-
text='MODE(e-encode, d-decode)'
89+
root, font='arial 12 bold', text='MODE(e-encode, d-decode)'
10690
).place(x=60, y=120)
10791
Entry(
108-
root,
109-
font='arial 10',
110-
textvariable=mode ,
111-
bg='ghost white'
112-
).place(x=290, y =120)
92+
root, font='arial 10', textvariable=mode , bg='ghost white'
93+
).place(x=290, y=120)
11394

11495
# result
11596
Entry(root,
116-
font='arial 10 bold',
117-
textvariable=Result,
118-
bg='ghost white'
119-
).place(x=290, y=150)
97+
font='arial 10 bold', textvariable=Result, bg='ghost white'
98+
).place(x=290, y=150)
12099

121100
# result button
122101
Button(
123-
root,
124-
font='arial 10 bold',
125-
text='RESULT' ,
126-
padx=2,
127-
bg='LightGray' ,
128-
command=Mode
102+
root, font='arial 10 bold', text='RESULT' , padx=2, bg='LightGray' , command=Mode
129103
).place(x=60, y=150)
130104

131105
# reset button
132106
Button(
133-
root,
134-
font='arial 10 bold' ,
135-
text='RESET' ,
136-
width=6,
137-
command=Reset,
138-
bg='LimeGreen',
139-
padx=2
107+
root, font='arial 10 bold' , text='RESET' , width=6,command=Reset, bg='LimeGreen', padx=2
140108
).place(x=80, y=190)
141109

142110
# exit button
143111
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)
112+
root, font='arial 10 bold', text='EXIT' , width=6, command=Exit, bg='OrangeRed', padx=2, pady=2
113+
).place(x=180, y=190)
152114
root.mainloop()

0 commit comments

Comments
(0)

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