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 68450bc

Browse files
Add files via upload
1 parent 3f0dd7a commit 68450bc

File tree

2 files changed

+116
-0
lines changed

2 files changed

+116
-0
lines changed

‎Cryptography/README.md‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
### This objective of this project is to encode and decode messages using a common key. This project will be built using the Tkinter and base64 library.
2+
3+
### In this project, users have to enter the message to encode or decode. Users have to select the mode to choose the encoding and decoding process. The same key must be used to process the encoding and decoding for the same message.
4+
5+
### Project Prerequisites-
6+
7+
### To build this project we will use basic concept of python, Tkinter, and base64 library.
8+
9+
### Tkinter is a standard GUI python library base64 module provides a function to encode the binary data to ASCII characters and decode that ASCII characters back to binary data.

‎Cryptography/crypto.py‎

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
##importing mmodules
2+
3+
from tkinter import *
4+
import base64
5+
6+
#initialize window
7+
root = Tk()
8+
root.geometry('500x300')
9+
root.resizable(0,0)
10+
11+
#title of the window
12+
root.title("Cryptography World")
13+
14+
15+
16+
#label
17+
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)
20+
21+
22+
#define variables
23+
24+
Text = StringVar()
25+
private_key = StringVar()
26+
mode = StringVar()
27+
Result = StringVar()
28+
29+
30+
#######define function#####
31+
32+
#function to encode
33+
34+
def Encode(key,message):
35+
enc=[]
36+
for i in range(len(message)):
37+
key_c = key[i % len(key)]
38+
enc.append(chr((ord(message[i]) + ord(key_c)) % 256))
39+
40+
return base64.urlsafe_b64encode("".join(enc).encode()).decode()
41+
42+
#function to decode
43+
44+
def Decode(key,message):
45+
dec=[]
46+
message = base64.urlsafe_b64decode(message).decode()
47+
for i in range(len(message)):
48+
key_c = key[i % len(key)]
49+
dec.append(chr((256 + ord(message[i])- ord(key_c)) % 256))
50+
51+
return "".join(dec)
52+
53+
#function to set mode
54+
def Mode():
55+
if(mode.get() == 'e'):
56+
Result.set(Encode(private_key.get(), Text.get()))
57+
elif(mode.get() == 'd'):
58+
Result.set(Decode(private_key.get(), Text.get()))
59+
else:
60+
Result.set('Invalid Mode')
61+
62+
63+
64+
#Function to exit window
65+
66+
def Exit():
67+
root.destroy()
68+
69+
70+
#Function to reset
71+
def Reset():
72+
Text.set("")
73+
private_key.set("")
74+
mode.set("")
75+
Result.set("")
76+
77+
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)
107+
root.mainloop()

0 commit comments

Comments
(0)

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