Prime Numbers Box project: learn cryptography
By Russell Barnes. Posted

Get a new prime number at the push of a button
Advertisement
The desktop computer you've been waiting for: Raspberry Pi 500+
Like all good geeks we love our prime numbers. They're one of the most interesting things to study in mathematics.
Maybe that's why we find this Prime Numbers in a Box project so endearing. It's pretty simple in practice, press a button; get a prime number.
"How many times have you needed the next prime number in a sequence and, like some animal, had to go to a printed table to look it up," says WhiskyTangoHotel. "Well, those days are over."
- Build information: Prime Numbers in a Box
The importance of prime numbers
These numbers are popular in encryption and cryptography. This is because the numbers, which are only divisible by themselves and one, can be multiplied together.
If you multiply two primes together, you get a public key. This number is used to lock data and can be shared freely. But to unlock the data, you need to know the two primes used to generate it.
While it's easy for a computer to generate the key from the two primes, it's very difficult for the computer to get the two numbers from the key.
There's a great video here by Simon Pampena that explains how prime numbers and cryptography work.
Learn about primes by building a box that generates them
While WhiskeyTangoHotels project doesn't create primes for cryptography. Instead, the build just celebrates the existence of these great numbers.
"The project has an entertaining audio effect if you are into numbers," says the maker. "Press a button and Primes in a Box gives an audible (relay click) signal for each non-prime as it waits to display the next found prime. If you enjoy mathematics, you may find this oddly relaxing."
"The Python source is pretty straightforward, explains the maker. "On button press, a pointer to a file containing the first few million primes is indexed and displayed on the LCD. A 5VDC relay clicks to represent the non-primes in between. The rig runs via USB power, and the last found prime is always saved. A handy 'shutdown' button is incorporated to allow the Raspberry Pi to be powered down gracefully if it needs to be moved."
You'll learn a few things about reading and writing to text files in this project. And you'll learn how to use an LCD and relay. More importantly, you'll never be short of primes again. And you might even be your first step towards becoming a cryptographer.

Russell runs Raspberry Pi Press, which includes The MagPi, Hello World, HackSpace magazine, and book projects. He’s a massive sci-fi bore.
Subscribe to Raspberry Pi Official Magazine
Save up to 37% off the cover price and get a FREE Raspberry Pi Pico 2 W with a subscription to Raspberry Pi Official Magazine.
More articles

Raspberry Pi 500+ in Raspberry Pi Official Magazine issue 158
We’re quite taken with Raspberry Pi 500+. But when you don’t need all that processing power, and just want a board that will make a plastic skeleton jump around in a terrifying manner, you’ll find Raspberry Pi Pico more than up to the job. There’s more terror in the magazine (which is only right as […]
Read more →

Win one of five Raspberry Pi SSD 1TB
Raspberry Pi prides itself on high quality hardware, and this 1TB Raspberry Pi SSD is no different. You can use it with a standard Raspberry Pi or even in your desktop PC – the choice is yours. We have five to give away and you can enter below Win 1 of 5 Raspberry Pi SSD […]
Read more →

Dual-screen cyberdeck
Twin screens mean you can code on one screen while watching David Bowie’s 1978 Musikladen show on the other.
Read more →
Sign up to the newsletter
Get every issue delivered directly to your inbox and keep up to date with the latest news, offers, events, and more.