Sei sulla pagina 1di 3

RSA Encryption

Mali Imre Gergely, Leiti David


2018
1 Introduction
The aim of this assignment was to implement a piece of software to simulate
RSA encryption. The program provides the following features:

• generate a new encryption key

• given a plain text, encrypt the text with the generated key(there will
be a plain text validation)

• givan a cipher text, compute the decryption key and decrypt the text
(there will be a cipher text validation)

2 Implementation
2.1 Technology
Our technology of choice was Python3.6 with PyQt5.11 for the UI. PyQt
offers a great variety of widgets that makes building interfaces easy and fast.

2.2 RSA
Our app uses the RSA class that encapsulates the logic of our application,
which is therefore being decoupled from the UI. Here we can find the implementations
of the Extended Euclidean Algorithm(EEA) and the Repeated Squaring
Modular Exponentiation. We use EEA for computing the greatest common
divisors of numbers as well as for computing the modular inverse of certain
numbers. This proves to be useful in the computation of the decryption key,
and in the generation of the public key.

We use an alphabet of the 26 letters of the English alphabet and space,


blocks of 2 characters at the encryption and blocks of 3 at the decryption.
Therefore, in the first step, we generate two prime numbers:

272 < p, q < 273 where p, qN

1
Then, we take:

n = p ∗ q and ϕ(n) = (p − 1)(q − 1)

Using the methods mentioned above we generate randomly:

e such that 1 < e < ϕ(n) and (e, ϕ(n)) = 1

This part of the algorithm is a probabilistic one, because in case the condition
regarding the greatest common divisors does not hold, we simply generate a
new one. However, due to the range of values we take our values from makes
the probability of not being able to generate a proper e in a reasonable time
is negligable.

The computation of the decryption key is done by a call to the EEA, as


it is computed with the following formula:

d = e−1 mod ϕ(n)

The encryption of a message is done by the following formula:

c = me mod n

Here m is the numerical representation of one block of message. Our


algorithm, using the blockToNumerical and numericalToBlock methods
transform blocks of characters to numbers in the corresponding ranges.

The decryption is done in a similar fashion, using the formula:

m = cd mod n

The validation of plain an cipher texts is being done based on the rules
that the plain text can only contain lowercase elements of our alphabet, while
the ciphertext can contain only uppercase ones. This can easily be checked
by using regular expressions.

For clarity, our program also offers information about the encryption and
decryption keys, that are being shown once we generate a key.

Potrebbero piacerti anche