07.07.2023 Views

Implementing-cryptography-using-python

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

226 Chapter 8 ■ Cryptographic Applications and PKI

that uses the two secret numbers, 11 and 17, to unlock the mathematical

padlock:

C 1/e mod (p – 1) (q – 1) mod N = M

165 1/13 mod (11 – 1) (17 – 1) = 88

With your algorithm being public, one could argue that someone can take the

secret key and find the factors used to produce it. Remember, multiplying is a

one-way operation, meaning it is difficult to go backward. Greater difficulty is

introduced as the numbers become larger. It wouldn’t take very long to find that

11 and 17 were the secret numbers when examining 187 since the only numbers

that factor into 187 are 1, 11, 17, and 187.

If you come up with two larger numbers that are 300 digits long, then your

padlock is secure. Factoring large numbers is hugely time-consuming. While

the math can get tough, Cocks invented a super secure encryption system and,

more importantly, he solved the key distribution problem. In the end, the Cocks

equation was the most important breakthrough in the history of secret codes.

The GCHQ was unable to implement the algorithm and classified it top secret,

keeping it closely guarded. In fact, it would remain top secret for another 24

years, even though a similar algorithm was published by Rivest, Shamir, and

Adleman in 1977.

Ron Rivest, Adi Shamir, and Leonard Adleman, researchers at the Massachusetts

Institute of Technology (MIT), developed a similar equation to Cocks’s

algorithm four years after Cocks. Their breakthrough was also attributed to

Rivest’s knowledge of number theory. This time, the discovery was in the public

arena. Knowing nothing about the British discovery, the team named their cipher

Rivest, Shamir, Adleman, better known as RSA. RSA has become one of the most

important ciphers ever introduced. Almost every time you transmit credit card

details online, the data is encrypted using RSA, making RSA the cornerstone

of a multi-billion-dollar e-commerce revolution. So, while the Americans were

not the first to invent public-key cryptography, they were the first to bring it

out into the public domain where anyone can use it. You can now communicate

as privately as a nation-state. You can send messages that cannot be cracked

even by the combined efforts of all the world’s secret services. For the first time

ever, you have access to unbreakable code. Cryptography may be the science

of secrecy, but through your continued practice, it is no longer a secret science.

Exploring the Basics of RSA

This first example is a simple implementation of the RSA algorithm that can

encrypt and decrypt a message. Note that the keys here are far too small to be

of practical use since they are still relatively easy to factor:

import random

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

Saved successfully!

Ooh no, something went wrong!