|
1 | | -## importing mmodules |
2 | 1 | from tkinter import Tk
|
3 | 2 | from tkinter import Label
|
4 | 3 | from tkinter import BOTTOM
|
|
16 | 15 | root.title("Cryptography World")
|
17 | 16 |
|
18 | 17 | # 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) |
21 | 20 |
|
22 | 21 | # define variables
|
23 | 22 | Text = StringVar()
|
|
26 | 25 | Result = StringVar()
|
27 | 26 |
|
28 | 27 |
|
29 | | -## define function ## |
30 | 28 | # function to encode
|
31 | 29 | def Encode(key, message):
|
32 | | - '''Takes the key and encode the message''' |
| 30 | + """Encode the message.""" |
33 | 31 | enc = []
|
34 | 32 | for i in enumerate(message):
|
35 | 33 | key_c = key[i % len(key)]
|
36 | 34 | enc.append(chr((ord(message[i]) + ord(key_c)) % 256))
|
37 | | - |
38 | 35 | return base64.urlsafe_b64encode("".join(enc).encode()).decode()
|
39 | 36 |
|
40 | 37 |
|
41 | 38 | # function to decode
|
42 | 39 | def Decode(key, message):
|
43 | | - '''Takes the key and decode the message''' |
| 40 | + """Decode the message.""" |
44 | 41 | dec = []
|
45 | 42 | message = base64.urlsafe_b64decode(message).decode()
|
46 | 43 | for i in enumerate(message):
|
47 | 44 | 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)) |
50 | 46 | return "".join(dec)
|
51 | 47 |
|
52 | 48 |
|
53 | 49 | # function to set mode
|
54 | 50 | def Mode():
|
55 | | - ''' Takes the mode of cryptography''' |
| 51 | + """Take mode of cryptography.""" |
56 | 52 | if mode.get() == 'e':
|
57 | 53 | Result.set(Encode(private_key.get(), Text.get()))
|
58 | 54 | elif mode.get() == 'd':
|
59 | 55 | Result.set(Decode(private_key.get(), Text.get()))
|
60 | 56 | else:
|
61 | 57 | Result.set('Invalid Mode')
|
62 | 58 |
|
63 | | -# Function to exit window |
| 59 | +# Function to exit window |
64 | 60 | def Exit():
|
65 | | - '''Exit the window''' |
| 61 | + """Exit the window.""" |
66 | 62 | root.destroy()
|
67 | 63 |
|
68 | | - |
69 | 64 | # Function to reset
|
70 | 65 | def Reset():
|
71 | | - ''' Used to reset the screen''' |
| 66 | + """Reset the screen.""" |
72 | 67 | Text.set("")
|
73 | 68 | private_key.set("")
|
74 | 69 | mode.set("")
|
75 | 70 | Result.set("")
|
76 | 71 |
|
77 | | - |
78 | | -## Label and Button ## |
| 72 | + |
79 | 73 | # Message
|
80 | 74 | Label(
|
81 | | - root, |
82 | | - font='arial 12 bold', |
83 | | - text='MESSAGE' |
| 75 | + root, font='arial 12 bold', text='MESSAGE' |
84 | 76 | ).place(x=60, y=60)
|
85 | 77 | Entry(
|
86 | | - root, |
87 | | - font='arial 10', |
88 | | - textvariable=Text, |
89 | | - bg='ghost white' |
| 78 | + root, font='arial 10', textvariable=Text, bg='ghost white' |
90 | 79 | ).place(x=290, y=60)
|
91 | 80 |
|
92 | 81 | # key
|
93 | 82 | Label(root, font='arial 12 bold', text='KEY').place(x=60, y=90)
|
94 | 83 | 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' |
99 | 85 | ).place(x=290, y=90)
|
100 | 86 |
|
101 | 87 | # mode
|
102 | 88 | 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)' |
106 | 90 | ).place(x=60, y=120)
|
107 | 91 | 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) |
113 | 94 |
|
114 | 95 | # result
|
115 | 96 | 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) |
120 | 99 |
|
121 | 100 | # result button
|
122 | 101 | 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 |
129 | 103 | ).place(x=60, y=150)
|
130 | 104 |
|
131 | 105 | # reset button
|
132 | 106 | 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 |
140 | 108 | ).place(x=80, y=190)
|
141 | 109 |
|
142 | 110 | # exit button
|
143 | 111 | 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) |
152 | 114 | root.mainloop()
|
0 commit comments