The Math in Public-key Cryptography — in simple words with examples (2024)

Published in

Techanic

·

6 min read

·

May 20, 2023

--

Public-key cryptography, also called as asymmetric key cryptography, is a method of encryption that uses two different keys — a public key and a private key — to encrypt and decrypt data. Public-key cryptography relies on mathematical functions that are easy to compute in one direction, but difficult to compute in the opposite direction. In this way, it ensures that only the intended recipient can decrypt the message, even if the encrypted message is intercepted by a third party.

The Math in Public-key Cryptography — in simple words with examples (3)

Public and private keys are created using mathematical functions based on modular arithmetic and the properties of co-prime numbers. Here is a step-by-step example of how public and private keys are created:

  1. Select two prime numbers: To create a public and private key pair, two different prime numbers must be selected. For example, let’s choose p = 17 and q = 23.
  2. Compute n: Compute the product of the two prime numbers. n = p * q = 17 * 23 = 391.
  3. Compute φ(n): Compute the Euler’s totient/phi function of n, which is the number of positive integers less than n that are co-prime to n. φ(n) = (p-1) * (q-1) = 16 * 22 = 352.
  4. Choose a co-prime number: Choose a number e that is co-prime to φ(n). In other words, e should have no common factors with φ(n) other than 1. For example, let e = 5.
  5. Compute the private key: Compute the private key d, which is the multiplicative/modular inverse of e modulo φ(n). In other words, d is the number such that (d * e) mod φ(n) = 1. In this example, d = 141.
  6. Public and Private Key Pair: The public key is (n, e) and the private key is (n, d).

To encrypt a message m using the public key (n, e), we first convert the message into a number m using a chosen encoding method. Then, we apply the encryption function C(m) = m^e mod n, which generates the encrypted message.

To decrypt the encrypted message C using the private key (n, d), we apply the decryption function D(C) = C^d mod n, which recovers the original message.

For example, let’s say we want to encrypt the message M = “HELLO” using the public key (391, 5). First, we convert the message into a number m = 72736576 using ASCII encoding. Then, we apply the encryption function C(m) = m^e mod n = 72736576⁵ mod 391 = 113.

To decrypt the encrypted message C = 113 using the private key (391, 141), we apply the decryption function D(C) = C^d mod n = 113¹⁴¹ mod 391 = 72736576, which recovers the original message “HELLO”.

Why prime numbers are used (17 and 23 in the example above) and why are they multiplied?

This is done because it is computationally difficult to factorize a large number into its prime factors, which provides security for the encryption algorithm. Solutions such as Eratosthenes sieve are used for prime factorization, however for a very large prime numbers, it is computationally expensive.

What are co-prime numbers?

Two positive integers are said to be co-prime if they have no common factors other than 1. In other words, their greatest common divisor (GCD) is 1. For example, 2 and 3 are co-prime since their only common factor is 1. On the other hand, 4 and 6 are not co-prime since they have a common factor of 2. Co-prime numbers are also known as relatively prime or mutually prime numbers.

What is multiplicative inverse and modular inverse?

The multiplicative inverse of a number is the number that, when multiplied by the original number, yields a product of 1. In other words, it is the reciprocal of the number. For example, the multiplicative inverse of 2 is 1/2, because 2 multiplied by 1/2 is equal to 1.

Extrapolating this idea to including a modulo would mean that if e is relatively prime (co-prime) to φ(n), i.e. gcd(e, φ(n)) = 1, then there exists a d such that d = 1/e mod φ(n), i.e d * e = 1 mod φ(n). For every e, if a d exists, then that d is unique.

Why use Euler’s Totient function or Euler’s Phi? And, why is it used?

φ(n) is number of positive integers less than n that are co-prime to n. φ(n) counts the positive integers that are less than or equal to n and are relatively prime to n. Let’s imagine we have two prime numbers, p and q. The product of these two numbers gives us n, which is used as the modulus for both the public and private keys in RSA. The totient of n, φ(n), is then calculated as (p-1)*(q-1). Let’s first prove that φ(n) = (p-1)*(q-1).

When n is a prime number, every number less than n is relatively prime to n, so φ(n) equals n-1 for a prime number n. We are working with n = p*q, where p and q are distinct prime numbers. The numbers that are not relatively prime to n are precisely the multiples of p and the multiples of q. There are q multiples of p less than n, and p multiples of q less than n.

But since p and q are distinct primes, the multiples intersect precisely at their common multiples, which are multiples of p*q = n. There is exactly one multiple of n less than n. In simpler words, when we say p and q are distinct primes, it means they are different prime numbers with no common factors other than 1. The numbers that are multiples of both p and q are exactly the multiples of their product, which is p*q. And in our case, p*q is equal to n.

So, the count of positive integers less than n that are not relatively prime to n is q (multiples of p) + p (multiples of q) — 1 (common multiples).

The count of positive integers less than n that are relatively prime to n is then n — the count of those that aren’t. Substituting the values, we get:

n — (p + q — 1) = pq — p — q + 1 = (p-1)(q-1), since n = pq. QED

The merit of using Euler’s totient lies in Euler’s theorem, which states that if p and q are co-prime numbers, then q to the power of φ(p) is congruent to 1 (mod p). This theorem underpins the mathematics that make public key cryptography, i.e. the encryption and decryption of it, work.

Without trying to prove Euler’s theorem, lets get into its foundations. If a number “a” is coprime to n (meaning “a” and n share no factors other than 1), then “a” raised to the power of the totient of n, is congruent to 1 modulo n. So, Euler’s theorem can be written as:

a^((p-1)(q-1)) ≡ 1 (mod n)

Thus Euler’s theorem gives us a neat trick for ‘undoing’ the encryption. When someone wants to send you a secret message, they ‘lock’ it using your public key, which involves raising their message (as a number) to the power of your public key, then looking at the remainder when they divide by “n”. To ‘unlock’ the message, you raise it to the power of your private key, and again look at the remainder when you divide by “n”. Euler’s theorem guarantees that this process will return the original message. Without Euler’s theorem and the use of the totient, we wouldn’t have a practical way to ‘unlock’ the encrypted message.

In the fascinating world of public-key cryptography, a cornerstone of data security in today’s digital age, mathematics plays an indispensable role. Central to this is Euler’s Theorem, a principle that underpins the secure exchange of information across networks. Through this mathematical mechanism, public-key cryptography allows the creation of two interlinked keys, one for encryption (public) and one for decryption (private), enabling secure communication in an increasingly interconnected world. Without Euler’s theorem and the ingenious application of its principles in public-key cryptography, the landscape of modern data security would look vastly different.

The Math in Public-key Cryptography — in simple words with examples (2024)

FAQs

How does public-key cryptography work in math? ›

Public key cryptography is based on the concept of mathematical functions that are easy to compute in one direction, but computationally infeasible to reverse. This means that while it is easy to encrypt data using the public key, it is extremely difficult to decrypt it without the corresponding private key.

How is math used in cryptography? ›

Another important mathematical concept in cryptography is number theory, which is the study of the properties of whole numbers. Prime numbers are of particular importance, as they are used to generate cryptographic keys, which are used to encode and decode messages.

What is public-key cryptography explained simply? ›

Public key cryptography is a method of encrypting or signing data with two different keys and making one of the keys, the public key, available for anyone to use. The other key is known as the private key.

What is the math formula for encryption? ›

The conversion formula is of the form c ≡ p + a mod 26. We know that when p = 5 (plaintext E), we have c = 10 (ciphertext J). Thus, 10 ≡ 5 + a mod 26. So a ≡ 5 37 Page 4 mod 26, and the encryption formula is c ≡ p + 5 mod 26.

What is the formula for public key encryption? ›

To encrypt a message m using the public key (n, e), we first convert the message into a number m using a chosen encoding method. Then, we apply the encryption function C(m) = m^e mod n, which generates the encrypted message.

What is the math behind RSA cryptography? ›

The RSA cryptosystem is composed of three steps: Key generation: Each user u generates two primes p,q, calculates n=pq and φ(n)=(p−1)(q−1), picks a random e (which must be relatively prime to φ(n)) and calculates d=e−1(modφ(n)). The user publishes the public key pubu=(n,e) and keeps for herself the private key priu=d.

Do you need to know math for cryptography? ›

It is recommended that you have a basic knowledge of computer science and basic math skills such as algebra and probability.

What is the essential mathematics for cryptography? ›

  • An Introduction to Cryptography.
  • Discrete Logarithms and Diffie-Hellman.
  • Integer Factorization and RSA.
  • Probability Theory and Information Theory.
  • Elliptic Curves and Cryptography.
  • Lattices and Cryptography.
  • Digital Signatures.
  • Additional Topics in Cryptology.

What kind of math is used in encryption? ›

Most encryption is based heavily on number theory, most of it being abstract algebra. Calculus and trigonometry isn't heavily used. Additionally, other subjects should be understood well; specifically probability (including basic combinatorics), information theory, and asymptotic analysis of algorithms.

What is the algorithm of public key cryptography? ›

Public key cryptography (asymmetric) uses encryption algorithms such as RSA and Elliptic Curve Cryptography (ECC) to create the public and private keys. These algorithms are based on the intractability of certain mathematical problems.

What is the public key cryptography theory? ›

The goal is to trick the sender into thinking that the attacker is the reciever, and to trick the receiver into thinking that the attacker is the sender; this is done by having the sender encrypt their message using the attacker's public key rather than the intended receiver's, allowing the attacker to decrypt the ...

What is the principle of public key cryptography? ›

Public-key cryptography, or asymmetric cryptography, is the field of cryptographic systems that use pairs of related keys. Each key pair consists of a public key and a corresponding private key. Key pairs are generated with cryptographic algorithms based on mathematical problems termed one-way functions.

What is cryptography in mathematics with examples? ›

Cryptography is the science of using mathematics to hide data behind encryption. It involves storing secret information with a key that people must have in order to access the raw data. Without cracking the cipher, it's impossible to know what the original is.

What is the formula for cryptography? ›

Caesar Cipher is one of the simple methods in cryptography. This method requires two inputs one a number and a plaintext. The Time Complexity and Space Complexity both are O(N). The encryption formula is En(x) = (x + n) mod 26 and the Decryption formula is Dn(x) = (x – n) mod 26.

What is the mathematical analysis of cryptography? ›

At the heart of cryptography lie several key mathematical concepts. Prime numbers and modular arithmetic, for instance, are fundamental to many cryptographic algorithms. Prime numbers are integers greater than one, which are only divisible by one and themselves.

What is public-key cryptography in number theory? ›

Public-Key Ciphers. public-key (or two-key) cryptography involves the use of two keys: a public-key, which may be known by anybody, and can be used to encrypt messages, and verify signatures. a private-key, known only to the recipient, used to decrypt messages, and sign (create) signatures.

How does symmetric encryption work mathematically? ›

A symmetric algorithm uses the same key to encrypt data as it does to decrypt data. For example, a symmetric algorithm will use key k to encrypt some plaintext information like a password into a ciphertext. Then, it uses k again to take that ciphertext and turn it back into the password.

How are asymmetric keys mathematically related? ›

Asymmetric encryption uses a mathematically related pair of keys for encryption and decryption: a public key and a private key. If the public key is used for encryption, then the related private key is used for decryption. If the private key is used for encryption, then the related public key is used for decryption.

Top Articles
Leveraging Limited Liability for personal asset protection
The Economic Impact of Food Waste | Shapiro
Golden Abyss - Chapter 5 - Lunar_Angel
Tyler Sis 360 Louisiana Mo
Tmf Saul's Investing Discussions
Amc Near My Location
Devon Lannigan Obituary
Archived Obituaries
Gabrielle Abbate Obituary
GAY (and stinky) DOGS [scat] by Entomb
J Prince Steps Over Takeoff
Jasmine
OnTrigger Enter, Exit ...
Walgreens On Nacogdoches And O'connor
MindWare : Customer Reviews : Hocus Pocus Magic Show Kit
What is the difference between a T-bill and a T note?
Hoe kom ik bij mijn medische gegevens van de huisarts? - HKN Huisartsen
The best TV and film to watch this week - A Very Royal Scandal to Tulsa King
White Pages Corpus Christi
Kountry Pumpkin 29
What Time Does Walmart Auto Center Open
27 Paul Rudd Memes to Get You Through the Week
Yugen Manga Jinx Cap 19
Drift Hunters - Play Unblocked Game Online
Restored Republic June 16 2023
Elite Dangerous How To Scan Nav Beacon
Victory for Belron® company Carglass® Germany and ATU as European Court of Justice defends a fair and level playing field in the automotive aftermarket
Darrell Waltrip Off Road Center
Craigslist Auburn Al
Stubhub Elton John Dodger Stadium
Craigslist Middletown Ohio
Bursar.okstate.edu
Sam's Club Near Wisconsin Dells
Citibank Branch Locations In Orlando Florida
Ma Scratch Tickets Codes
Craigslist Hamilton Al
How to Watch the X Trilogy Starring Mia Goth in Chronological Order
Edict Of Force Poe
Why Gas Prices Are So High (Published 2022)
Body Surface Area (BSA) Calculator
Tyler Perry Marriage Counselor Play 123Movies
Achieving and Maintaining 10% Body Fat
Crystal Glassware Ebay
Craigslist Mendocino
20 Mr. Miyagi Inspirational Quotes For Wisdom
Hampton In And Suites Near Me
Blog Pch
Brutus Bites Back Answer Key
10 Bedroom Airbnb Kissimmee Fl
The Goshen News Obituary
Tamilblasters.wu
Latest Posts
Article information

Author: Ouida Strosin DO

Last Updated:

Views: 6573

Rating: 4.6 / 5 (76 voted)

Reviews: 91% of readers found this page helpful

Author information

Name: Ouida Strosin DO

Birthday: 1995-04-27

Address: Suite 927 930 Kilback Radial, Candidaville, TN 87795

Phone: +8561498978366

Job: Legacy Manufacturing Specialist

Hobby: Singing, Mountain biking, Water sports, Water sports, Taxidermy, Polo, Pet

Introduction: My name is Ouida Strosin DO, I am a precious, combative, spotless, modern, spotless, beautiful, precious person who loves writing and wants to share my knowledge and understanding with you.