Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

IN PYTHON - design and build a working (SIMPLE) RSA encryption/decryption scheme. It does not need to be secure that would require large prime numbers

IN PYTHON - design and build a working (SIMPLE) RSA encryption/decryption scheme. It does not need to be secure that would require large

prime numbers but it should force a would be hacker to use brute force methods to

crack the encryption. Here we will work with algorithms to illustrate the basic principles of RSA encryption.

functions:

generating encryption keys from random prime numbers, and encrypting / decrypting integer

representations of a text string.

a) Generate two random prime numbers p and q, from which you can compute the modulus and totient

n=pq

and the totient

=(p1)(q1).

b) Find the private exponent d from the public exponent e= 65537 and the totient phi.

c) Generate 20 random integers in the range n /10 to (n 1) to test the method

d) Encrypt and decrypt your list of integers

e) Check that the list of decrypted integers is identical to the original list.

First create a main() function for output similar to the sample at the bottom. It should print the

number of bits you are using for encryption/decryption, the prime numbers and the

public / private keys you generated, the original (plain) list of integers, the encrypted list, and the decrypted list.

use only 16-bit encryption, which is very fast. All you will need are the simplest methods, described in the notes below.

Additional Notes:

a) p and q - use isPrime(), random.randint(M/10, M) without (by chance) getting a very small p/q. M=2^(b/2), (n = pq) < 2 The

largest prime M is connected to the number of bits you will use to encrypt the integers.

-make sure that the totient is not a multiple of the public exponent e ; otherwise generate a new pair of primes.

b) The simplest way to calculate the private exponent is to check the integers d one at a time, then check if

ed1(mod) is satisfied write a function to do that and return the public key (e,n) and the private key (d,n).

c) then encrypt/decrypt some integers generate 20 random integers that must be less than the modulus

pq so use a range pq/10 to pq-1. In real world applications, text strings are always padded to make them fill most

of the available bits short text strings are too easy to crack.

d) The encryption and decryption steps use modular arithmetic: if the unencrypted integer is k, then the encrypted integer

m is found from m k e(mod n) and the decrypted integer k dec m d(modn) should be equal to k. The equivalent operations in Python

are: m = (k**e)%n and kdec = (m**d)%n.

e) The final step is to check that the list of decrypted integers is identical to the original list.

You will know everything is working when you get the same list of integers back at

the end.

Enter number of bits: 16

16 bit encryption

Using primes: 79 67

Public key: 5293 65537

Private key: 5293 4157

Original integers

[3656, 747, 2214, 3263, 2624, 978, 1693, 1290, 1218, 3776,

2942, 4160, 4813, 3163, 2984, 1338, 3839, 3586, 3325, 2341]

Encrypted integers

[4050, 2995, 1117, 4164, 61, 3077, 4463, 1947, 2239, 3766,

1150, 324, 341, 5183, 1595, 2847, 1531, 4914, 946, 2864]

Decrypted integers

[3656, 747, 2214, 3263, 2624, 978, 1693, 1290, 1218, 3776,

2942, 4160, 4813, 3163, 2984, 1338, 3839, 3586, 3325, 2341]

***Decrypted integers identical to original***

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Knowledge Discovery In Databases

Authors: Gregory Piatetsky-Shapiro, William Frawley

1st Edition

0262660709, 978-0262660709

More Books

Students also viewed these Databases questions