Question

In: Computer Science

Using Tkinter for GUI, A Python program that will allow the user to perform (i) generate...

Using Tkinter for GUI, A Python program that will allow the user to perform (i) generate RSA keys, (ii) encrypt a given message and (iii) decrypt the message without using any cryptographic library. Your program will generate the values of p unless the user provides them manually. Then the program will generate the keys (private and public). Then the program will allow the user to enter his/her message to be encrypted. Finally, the program will perform the decryption operation as well. Subtask and mark distribution:

• Friendly and logical GUI [5 marks]

• Key generation [8 marks]

• Encryption [3 marks]

• Decryption [3 marks]

• Performance enhancement [8 marks] : Due to the limitation of the size of integer type variables, many operations such as xy, xy etc. would not be possible when the value of x, y will be very high. Hence, you would not be able to work with big prime numbers. By definition, this will provide a weak RSA. Under this task you have to optimize the algorithm and implementation to support bigger number. You have to include an extra section in the report to explain how you have achieved this enhancement.

NOTE: User should be able to use the GUI to encrypt/decrypt the message. The task is more like making an app for encryption/decryption using Tkinter.

Solutions

Expert Solution

PROGRAM :

import math

print("RSA ENCRYPTION/DECRYPTION")
print("*****************************************************")

#Input Prime Numbers
print("PLEASE ENTER THE 'p' AND 'q' VALUES BELOW:")
p = int(input("Enter a prime number for p: "))
q = int(input("Enter a prime number for q: "))
print("*****************************************************")

#Check if Input's are Prime
'''THIS FUNCTION AND THE CODE IMMEDIATELY BELOW THE FUNCTION CHECKS WHETHER THE INPUTS ARE PRIME OR NOT.'''
def prime_check(a):
if(a==2):
return True
elif((a<2) or ((a%2)==0)):
return False
elif(a>2):
for i in range(2,a):
if not(a%i):
return false
return True

check_p = prime_check(p)
check_q = prime_check(q)
while(((check_p==False)or(check_q==False))):
p = int(input("Enter a prime number for p: "))
q = int(input("Enter a prime number for q: "))
check_p = prime_check(p)
check_q = prime_check(q)

#RSA Modulus
'''CALCULATION OF RSA MODULUS 'n'.'''
n = p * q
print("RSA Modulus(n) is:",n)

#Eulers Toitent
'''CALCULATION OF EULERS TOITENT 'r'.'''
r= (p-1)*(q-1)
print("Eulers Toitent(r) is:",r)
print("*****************************************************")

#GCD
'''CALCULATION OF GCD FOR 'e' CALCULATION.'''
def egcd(e,r):
while(r!=0):
e,r=r,e%r
return e

#Euclid's Algorithm
def eugcd(e,r):
for i in range(1,r):
while(e!=0):
a,b=r//e,r%e
if(b!=0):
print("%d = %d*(%d) + %d"%(r,a,e,b))
r=e
e=b

#Extended Euclidean Algorithm
def eea(a,b):
if(a%b==0):
return(b,0,1)
else:
gcd,s,t = eea(b,a%b)
s = s-((a//b) * t)
print("%d = %d*(%d) + (%d)*(%d)"%(gcd,a,t,s,b))
return(gcd,t,s)

#Multiplicative Inverse
def mult_inv(e,r):
gcd,s,_=eea(e,r)
if(gcd!=1):
return None
else:
if(s<0):
print("s=%d. Since %d is less than 0, s = s(modr), i.e., s=%d."%(s,s,s%r))
elif(s>0):
print("s=%d."%(s))
return s%r

#e Value Calculation
'''FINDS THE HIGHEST POSSIBLE VALUE OF 'e' BETWEEN 1 and 1000 THAT MAKES (e,r) COPRIME.'''
for i in range(1,1000):
if(egcd(i,r)==1):
e=i
print("The value of e is:",e)
print("*****************************************************")

#d, Private and Public Keys
'''CALCULATION OF 'd', PRIVATE KEY, AND PUBLIC KEY.'''
print("EUCLID'S ALGORITHM:")
eugcd(e,r)
print("END OF THE STEPS USED TO ACHIEVE EUCLID'S ALGORITHM.")
print("*****************************************************")
print("EUCLID'S EXTENDED ALGORITHM:")
d = mult_inv(e,r)
print("END OF THE STEPS USED TO ACHIEVE THE VALUE OF 'd'.")
print("The value of d is:",d)
print("*****************************************************")
public = (e,n)
private = (d,n)
print("Private Key is:",private)
print("Public Key is:",public)
print("*****************************************************")

#Encryption
'''ENCRYPTION ALGORITHM.'''
def encrypt(pub_key,n_text):
e,n=pub_key
x=[]
m=0
for i in n_text:
if(i.isupper()):
m = ord(i)-65
c=(m**e)%n
x.append(c)
elif(i.islower()):
m= ord(i)-97
c=(m**e)%n
x.append(c)
elif(i.isspace()):
spc=400
x.append(400)
return x


#Decryption
'''DECRYPTION ALGORITHM'''
def decrypt(priv_key,c_text):
d,n=priv_key
txt=c_text.split(',')
x=''
m=0
for i in txt:
if(i=='400'):
x+=' '
else:
m=(int(i)**d)%n
m+=65
c=chr(m)
x+=c
return x

#Message
message = input("What would you like encrypted or decrypted?(Separate numbers with ',' for decryption):")
print("Your message is:",message)

#Choose Encrypt or Decrypt and Print
choose = input("Type '1' for encryption and '2' for decrytion.")
if(choose=='1'):
enc_msg=encrypt(public,message)
print("Your encrypted message is:",enc_msg)
print("Thank you for using the RSA Encryptor. Goodbye!")
elif(choose=='2'):
print("Your decrypted message is:",decrypt(private,message))
print("Thank you for using the RSA Encryptor. Goodbye!")
else:
print("You entered the wrong option.")
print("Thank you for using the RSA Encryptor. Goodbye!")

OUTPUT:

For encryption :

For decryption :


Related Solutions

Write a GUI based Python program that will allow the user to perform (i) generate RSA...
Write a GUI based Python program that will allow the user to perform (i) generate RSA keys, (ii) encrypt a given message and (iii) decrypt the message without using any cryptographic library. Your program will generate the values of p unless the user provides them manually. Then the program will generate the keys (private and public). Then the program will allow the user to enter his/her message to be encrypted. Finally, the program will perform the decryption operation as well....
In python using tkinter, I want to create a program. The program can have various classes...
In python using tkinter, I want to create a program. The program can have various classes and methods but I want it to have circles, triangles, and squares. Each shape movies in a certain way, like circles can move linearly, triangles can be affected by gravity, and squares can only go up and down. If the shapes get too close to one another then they disappear and a new shape appears somewhere else. I want this program to run continuously.
Python Using tkinter, create a GUI interface which accepts input of a GPA. If the GPA...
Python Using tkinter, create a GUI interface which accepts input of a GPA. If the GPA is >= 3.5, display 'Dean’s List' If the GPA is < 2.0, display 'Probation’ If the GPA is < 3.5 and >= 2.0, display 'Regular Standing' Run one test case for each case above and save the output.
Write a python program that will allow a user to draw by inputting commands. The program...
Write a python program that will allow a user to draw by inputting commands. The program will load all of the commands first (until it reaches command "exit" or "done"), and then create the drawing. Must include the following: change attributes: color [red | green | blue] width [value] heading [value] position [xval] [yval] drawing: draw_axes draw_tri [x1] [y1] [x2] [y2] [x3] [y3 draw_rect [x] [y] [b] [h] draw_poly [x] [y] [n] [s] draw_path [path] random random [color | width...
The objective of this project is to practice using Pythons GUI tkinter. You must use tkinter...
The objective of this project is to practice using Pythons GUI tkinter. You must use tkinter and no other GUI product. Design a small (ie 2x3) GUI window which contains 4 items: 1. A text keyin field, 2. An Execute button, 3. An Exit Button 4. A label. When the user clicks on the execute button, the text located in the keyin field will be displayed on the label. If the keyin field contains no text, a message box should...
Python Create a tkinter GUI application that has two buttons on it. The first button should...
Python Create a tkinter GUI application that has two buttons on it. The first button should have in red text the word "Red" on it and the second button should have in blue text the word "Blue" on it. When the red button is clicked you should change the background color of the application window to red and when the blue button is pressed you should change the background color of the application window to blue. You should place your...
I NEED TO CREATE A GUI INTERFACE USING TKINTER CONTAINING : Colors, Image, Button, Title bar,...
I NEED TO CREATE A GUI INTERFACE USING TKINTER CONTAINING : Colors, Image, Button, Title bar, and a Menu bar FOR THE QUESTION BELOW: PLEASE HELP PROGRAMMING LANGUAGE IS PYTHON Write a simple quiz game that has a list of ten questions and a list of answers to those questions. The game should give the player four randomly selected questions to answer. It should ask the questions one-by-one, and tell the player whether they got the question right or wrong....
CODE IN PYTHON: Your task is to write a simple program that would allow a user...
CODE IN PYTHON: Your task is to write a simple program that would allow a user to compute the cost of a road trip with a car. User will enter the total distance to be traveled in miles along with the miles per gallon (MPG) information of the car he drives and the per gallon cost of gas. Using these 3 pieces of information you can compute the gas cost of the trip. User will also enter the number of...
create a program that asks user math questions and keeps track of answers... Python Allow the...
create a program that asks user math questions and keeps track of answers... Python Allow the user to decide whether or not to keep playing after each math challenge. Ensure the user’s answer to each math problem is greater than or equal to zero. Keep track of how many math problems have been asked and how many have been answered correctly. When finished, inform the user how they did by displaying the total number of math problems, the number they...
***USING JAVA Scenario: You will be writing a program that will allow a user to find...
***USING JAVA Scenario: You will be writing a program that will allow a user to find and replace misspelled words anywhere in the phrase, for as many words as the user wishes. Once done (see example runs below), the program will print the final phrase and will show the Word Count, Character Count, the Longest Word and the Shortest Word. Requirements: Do not use Arrays for this assignment. Do not use any String class methods (.phrase(), replace methods, regex methods)...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT