December 5, 2026

RSA Encryption by Hand: A Toy Key, a Secret Message, and How It Breaks

A brass padlock with two different keys on slate

The message “ATTACK AT DAWN,” encrypted with a genuine RSA public key, comes out as fourteen numbers: 2790, 2159, 2159, 2790, 641, 597, 1992 and so on. Anyone with the public key can read it back without ever touching the private key, factoring anything or doing any clever mathematics. All it takes is encrypting each of the 95 printable keyboard characters with that same public key and matching the results like a phrasebook. That attack took a fraction of a second, and it works on a key of any size if the message is encrypted the way most textbook examples show. RSA is sound. The textbook version of it is not.

Video: Eddie Woo on YouTube

The idea in one paragraph

Two keys, one lock

RSA, named for Rivest, Shamir and Adleman, was invented in 1977, according to a University of California San Diego announcement about a factoring record. Its security, as that release puts it, rests on the belief that it is difficult to factor large integers of a specific form. Anyone can encrypt with a public key. Only the holder of the matching private key can decrypt. And the private key can be computed from the public one only by someone who can split a huge number into its two prime factors.

What the numbers are

A key starts with two primes, p and q, multiplied into a modulus n. A public exponent e and the modulus form the public key. The private exponent d is chosen so that raising a number to the power e and then to the power d, both modulo n, gets back to the starting number. Finding d requires knowing (p − 1)(q − 1), and knowing that requires knowing p and q.

A calculator and notebook on a study table

Building a key small enough to see

The primes

A Python script built the classic teaching example. With p = 61 and q = 53:

Quantity Value
n = p × q 3233
(p − 1)(q − 1) 3120
Public exponent e 17
Private exponent d 2753

The public key is the pair (3233, 17). The private key is 2753. A quick check confirms they fit: 17 × 2753 = 46,801, which is 15 × 3120 + 1, so the two exponents undo each other modulo 3120.

Encrypting two letters

The letters H and I have the character codes 72 and 73. Encrypting each one means raising it to the 17th power and keeping the remainder after dividing by 3233. The script got 3000 for H and 1486 for I. Decrypting means raising each of those to the 2753rd power modulo 3233, which returns 72 and 73, and the message reads “HI” again. The numbers involved get enormous in principle, since 3000 raised to the 2753rd power has thousands of digits, but modular arithmetic keeps every step below 3233.

Why the toy key is useless

The modulus 3233 has only two factors, and a computer finds them instantly. The script’s factoring routine returned 53 and 61 in microseconds. With p and q in hand, anyone can repeat the key-building steps and compute d = 2753. Every real RSA key is the same construction with numbers hundreds of digits long. The factoring step is the only thing standing between a published key and its private partner.

How fast factoring gets hard

A timing experiment

To see the difficulty grow, the script generated random moduli as products of two primes of equal size and timed SymPy’s general factoring routine on each, on an ordinary cloud machine:

Modulus size Time to factor
20 bits under 0.0001 s
40 bits 0.0014 s
60 bits 0.0006 s
69 bits 0.16 s
89 bits 0.49 s
100 bits 0.72 s
109 bits 0.92 s
120 bits 3.25 s
129 bits 0.43 s
139 bits 25.05 s

Reading the noise

The times jump around, because the factoring methods in a general-purpose library depend on luck and on the particular numbers: the 129-bit modulus fell faster than the 120-bit one. The trend is still unmistakable. Somewhere around 140 bits, a single machine running general software needs tens of seconds, and every additional handful of bits multiplies the cost.

Where the record stands

Real keys are far beyond this range. Paul Zimmermann’s list of integer factoring records gives RSA-250, a 250-digit number, as the largest integer factored with a general-purpose algorithm, completed on February 28, 2020, by Fabrice Boudot, Pierrick Gaudry, Aurore Guillevic, Nadia Heninger, Emmanuel Thomé and Paul Zimmermann. The team’s announcement puts the total computation at roughly 2,700 core-years on 2.1 GHz Intel Xeon Gold 6130 processors: 2,450 for sieving and 250 for the matrix step. UC San Diego’s release adds that each of the two prime factors has 125 decimal digits and the work ran on tens of thousands of machines over a few months.

A server room aisle lined with metal equipment racks

What real keys look like

Key sizes and security levels

The National Institute of Standards and Technology rates RSA keys by equivalent “bits of security,” the effort an attacker would need. The table reproduced on keylength.com from NIST SP 800-57 lists a 1024-bit RSA modulus at 80 bits of security, 2048 bits at 112, 3072 bits at 128, 7680 bits at 192 and 15,360 bits at 256.

The calendar

The same page notes that 112-bit security strength “is acceptable through 2030 and deprecated after 2030,” and that NIST IR 8547 deprecates these algorithms after 2030 and disallows them after 2035, whatever the key size. That last date reflects a different threat, quantum computers, rather than faster factoring on ordinary machines.

The gap in numbers

The largest public factoring record, at 250 decimal digits, sits well short of the 2048-bit keys that NIST rates at 112 bits of security. Written out in decimal, a 2048-bit modulus runs to about 617 digits, roughly two and a half times the length of RSA-250. The toy modulus 3233 needs just 12 bits. Every digit added to a modulus multiplies the work of the best known methods, which is why 2,700 core-years bought only 250 digits. The timing table above stops at 139 bits, a few seconds’ work. Between those numbers lies the entire practical security of RSA as used today.

The phrasebook attack

Encrypting letter by letter

Textbook RSA is deterministic: the same input and the same public key always produce the same output. That turns letter-by-letter encryption into a substitution cipher with extra steps. The script encrypted “ATTACK AT DAWN” one character at a time with the public key (3233, 17):

2790, 2159, 2159, 2790, 641, 597, 1992, 2790, 2159, 1992, 1759, 2790, 604, 3165

The repeated numbers give it away immediately. 2790 appears four times and 2159 three times, exactly matching the A’s and T’s.

Breaking it without the private key

An attacker doesn’t need the repetition. The public key is public, so the attacker encrypts every printable character, codes 32 through 126, and builds a lookup table from ciphertext to letter. Matching the fourteen numbers against the table recovered “ATTACK AT DAWN” in full. The private key never entered the calculation, and the attack would work exactly the same way against a 4096-bit key.

Small messages, same problem

The general lesson is that encrypting anything from a small set of possible messages, such as single characters, yes-or-no answers, salaries rounded to the thousand or four-digit PINs, lets an attacker simply try them all with the public key.

Metal letterpress type set in a case

How real RSA avoids it

Padding with randomness

Real RSA never encrypts the raw message. It first wraps the message in a structured encoding that includes random bytes, so the same message encrypts differently every time. The Internet standard for RSA, RFC 8017, published in November 2016, notes that the encoding operation “may introduce some randomness” and that this has benefits for provable security.

Which padding

RFC 8017 states that “RSAES-OAEP is REQUIRED to be supported for new applications” and that the older scheme, “RSAES-PKCS1-v1_5 is included only for compatibility with existing applications.” OAEP, optimal asymmetric encryption padding, mixes the message with a random seed through hash functions before the RSA step, which defeats the phrasebook attack: encrypting “A” twice gives two unrelated ciphertexts.

RSA usually encrypts a key, not a message

RSA is also a poor tool for long messages. A common design generates a random key for a fast symmetric cipher, encrypts the bulk data with that, and uses RSA only to protect the random key. The toy example above, with its letter-by-letter encryption, is useful precisely because it shows every step that real implementations add protection around. The mathematics is a few lines of modular arithmetic. Using it safely takes a full standards document, and the phrasebook attack is a short demonstration of why.

Sources

  • UC San Diego, “New record set for cryptographic challenge” (March 2020): https://cse.ucsd.edu/node/2053
  • Paul Zimmermann, Integer Factoring Records: https://members.loria.fr/PZimmermann/records/factor.html
  • Factorization of RSA-250 announcement (February 28, 2020): https://caramba.loria.fr/rsa250.txt
  • keylength.com, NIST key length recommendations (SP 800-57 Part 1 Rev. 5 table): https://www.keylength.com/en/4/
  • RFC 8017, PKCS #1: RSA Cryptography Specifications Version 2.2: https://www.rfc-editor.org/rfc/rfc8017

719 Posts

Peter Kalafatis writes and edits X9M8. He holds a bachelor's degree from LIU Post and a master's in Media Studies from The New School, with academic work in the philosophy of science, human behavior, AI, and memetics.

View All Posts

One Response to “RSA Encryption by Hand: A Toy Key, a Secret Message, and How It Breaks”

  1. Darwin Turing Dawkins Review: Adleman's Prene Theory

    […] toward a general theory of evolution for more than 40 years (arXiv PDF). The x9m8 walkthrough of RSA encryption by hand covers the cryptography side of his career; this book is the other side, and it reads like a long […]

Leave a Reply

Your email address will not be published. Required fields are marked *