07.07.2023 Views

Implementing-cryptography-using-python

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

224 Chapter 8 ■ Cryptographic Applications and PKI

something had to be done, which led to the development of the holy grail of

cryptography. In this chapter, you will learn about a secret code so ingenious

that it would change the way we communicate forever. Through this chapter,

you gain cryptographic knowledge as you:

■■

Gain an understanding of the importance of PKI

■■

Learn how to implement a PKI solution in Python

■■

Gain an understanding of RSA

■■

Learn how to implement ElGamal

■■

Gain an understanding of Elliptic Curve Cryptography

■■

Learn how to implement a key exchange using Diffie-Hellman

The Public-Key Transformation

In 1975, Martin Hellman, Whitfield Diffie, and Ralph Merkle were working in

the electrical engineering department at Stanford University; unlike most cryptographers,

they worked outside the classified world of military intelligence. The

team proposed that, instead of the sender being responsible for encryption, the

receiver of the message would be responsible. The proposal asks the receiver for

their padlock to lock up the sender’s message. The system works because the

participants are exchanging padlocks and not the keys themselves. The keys are

always with the receiver; this mitigates the keys falling into the wrong hands.

Since it is not practical to send physical padlocks, the team had to invent a way

to create a mathematical padlock; these are often referred to as trapdoors. The

mathematical padlock had to be easy to lock but difficult to unlock without the

key. Developing the mathematical padlock was not a trivial process since most

operations are easy to do one way and easy to reverse. An example is taking a

number and then doubling it; for this example, if x = 20, and y = 2 * x, then y =

40. To reverse the process, it is easy to find half of y: x = y/2. This is an example

of two-way operation. To find the perfect mathematical padlock, it is necessary

to find a one-way operation. Multiplication is the perfect tool. If you are given

two four-digit numbers and asked to multiply the two numbers together, you

can easily complete the task. However, if you are given the product and asked

to work backward, that is a much harder problem to solve. To illustrate this

example, let’s assume you start with the number 3,261,611. Can you provide

the two numbers used to produce the number (aka factoring)? Where would

you start?

Multiplying two large integers together creates a mathematical lock, but it is

also a lock without a key. As such, it is an operation that is irreversible unless

you have the mathematical equivalent of a key. Enter Clifford Cocks; Cocks

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!