LIVE NEWSROOM · --:-- · May 23, 2026
A LIBRARY FOR SECURITY RESEARCHERS

What is the RSA algorithm with example

Post on X LinkedIn
What is the RSA algorithm with example

Hello everyone 🙂 Lucifer is here to explain to you guys what is RSA algorithm and how it works. Today in this article we are going to understand the working of the RSA algorithm with some examples that what is going over there.

After reading this article you’ll be able to know the working of RSA and be able to do mathematical calculations of the RSA algorithm. RSA is a Block cipher.

RSA (Rivest, Shamir, Adleman) algorithm was first described in 1977. It is an asymmetric cryptography algorithm with private and public keys in it. The public key is used for encryption and the private key is used for decryption.

rsa algorithm

// 01 Steps to calculate RSA

1. Key Generation

  1. Select two prime numbers p and q respectively
  2. Calculate n=p*q
  3. calculate Φ(n)=(p-1)*(q-1)
    • Euler’s Totient Function
  4. Exponential GCD [Φ(n), e] = 1
    • Condition = 1<e<Φ(n)
    • GCD = Greatest Common Division
  5. Calculate [de mod Φ(n) = 1]
  6. Public key = [e, n]
  7. Private key = [d, n]

2. Encryption

  • c = me mod n
    • [m = plaintext]
    • [m < n]
    • [c = ciphertext]
    • [m will be no. of words in your message]

3. Decryption

  • m = cd mod n

// 02 Example -1 RSA algorithm

Let's understand with an example

Assume p = 3, q = 11
n = 3x11 = 33                                        [i.e. n = pxq]
Φ(n) =  2x10 = 20                                 [i.e Φ(n) = (p-1)(q-1)]

So, let's take
e = 7 [1<7<20 and gcd ((7,20) = 1) ]

Now,

de mod Φ(n) = 1
7xd mod Φ(n) = 1
7xd mod 20 = 1        [ *** d = 3]

Since e = 7, d = 3

Public key = [e, n] = [7, 33]
Private key = [d, n] = [3, 33]

Let's take message = 31

Encryption

c = me mod n
c = 317 mod 33
c = 27512614111 mod 33
c = 4

Decryption

m = cd mod n 
m = 43 mod 33
m = 64 mod 33
m = 31

Note:-

[e, n] is a public key used in encryption, and [d, n] is a private key used for decryption.

// 03 Example – 2 RSA algorithm

Let's see another example

Assume p = 61, q = 53
n = 61x53 = 3233                                        [i.e. n = pxq]
Φ(n) = 60x52 = 3120                                 [i.e Φ(n) = (p-1)(q-1)]

So, let's take
e = 17 [1<17<3120 and gcd ((17, 3120) = 1) ]

Now,

de mod Φ(n) = 1
17xd mod Φ(n) = 1
17xd mod 3120 = 1        [ *** d = 2753]

Since e = 17, d = 2753

Public key = [e, n] = [17, 3233]
Private key = [d, n] = [2753, 3233]

Let's take message = 123

Encryption

c = me mod n
c = 12317 mod 3233
c = 855

Decryption

m = cd mod n 
m = 8552753 mod 3233
m = 123

// 04 Usage of the RSA algorithm

  1. This uses in banks for securing customer data and transaction details
  2. It uses in telecommunication for encrypting call data
  3. Uses in e-commerce for securing users’ identity for transactions
https://youtu.be/wAOI2jzdwbo

    TE
    Team Ciphers Security

    The Ciphers Security editorial team — practitioners covering daily threat intel, CVE deep-dives, and hands-on cybersecurity research. About us →

    Previous What are IP Address and MAC Address explaination Next Data Encryption Standard (DES) algorithm with diagram

    Latest News

    Megalodon: Supply Chain Attack Backdoors 5,561 GitHub Repos in Six Hours via CI/CD Workflow Injection Megalodon supply chain attack compromised 5,561 GitHub repos in 6 hours on May 18, injecting malicious CI/CD workfl… Stolen Gemini API Keys and AI Fraud: How 'Quantum Patriot' Drained Crypto Wallets via Fake QAnon Content A Russian-speaking fraudster used 73 stolen Gemini API keys and an automated Python pipeline to generate fake QAnon… Stack String Obfuscation in C: The Technique That Blinds AV, YARA, and Static Scanners Stack strings let malware hide C2 URLs and API names from static analysis. Learn how the technique works in C, whic… YARA-X 1.16.0: Faster Scans, Panic Fixes, and Neovim LSP Support YARA-X 1.16.0 ships with performance improvements across 10 PRs, constant folding for bitwise ops, configurable mat… Instructure Removed from ShinyHunters' Leak Site as Canvas Breach Deadline Passes Instructure was quietly removed from ShinyHunters' extortion site after the May 12, 2026 deadline — no data dump, n… Costa Rica Joins Have I Been Pwned as the 42nd Government Costa Rica's CSIRT gains free access to Have I Been Pwned's government domain monitoring service, becoming the 42nd… LummaC2 Infostealer Targets US Critical Infrastructure: CISA-FBI Advisory AA25-141B and DOJ Domain Seizures CISA and FBI advisory AA25-141B details LummaC2 MaaS infostealer TTPs targeting critical infrastructure. DOJ seized… MacSync Stealer: Hackers Abuse Google Ads and Claude.ai Chats to Push Mac Malware Russian-speaking attackers combine Google Ads and Claude.ai shared chats in a ClickFix campaign deploying MacSync S…
    Scroll to Top
    Ad