CantorCipher: A Personal Encryption Project Inspired by Cantor’s Diagonal Argument



This content originally appeared on DEV Community and was authored by Armin Memar

I’m a self-taught cryptography enthusiast and high school graduate who loves exploring the intersection of mathematics and programming.
This is the story behind CantorCipher— a lightweight, educational encryption algorithm I built from scratch using ideas from Cantor’s diagonal argument and Boolean logic.

Why I Created CantorCipher
During my study of cryptographic concepts, I became fascinated with how mathematics can drive real-world technology. One particular concept stuck with me: Cantor’s diagonal argument — a brilliant proof technique from set theory that shows how infinities can be “bigger” than other infinities.

It made me think:

What if we used diagonalization to create structure and uniqueness in cryptography?

That’s when the idea for CantorCipher was born — a symmetric block cipher that mixes bits based on mathematical rules, using Boolean logic and custom-designed bit mixing. I wanted something simple, deterministic, and mathematically elegant!

What Is CantorCipher?
CantorCipher is a symmetric encryption algorithm that:

  • Converts messages and keys into binary
  • Applies several rounds of Boolean logic mixing (XOR, AND, NOT, etc.)
  • Uses diagonal-based patterns to compute an authentication tag
  • Supports both encryption and decryption in Python

It’s not designed to compete with AES or ChaCha, but rather to show how encryption can be built creatively using bit-level logic and mathematical structure.

Core Design

  • Boolean Logic: The cipher is built on fundamental logic operations like XOR, AND, and custom nonlinear bit rules.
  • Diagonalization: A metaphorical application of Cantor’s diagonal method to ensure message–key uniqueness in tag generation.
  • Bit Mixing: Rotations, permutations, and multi-round mixing create diffusion and a basic avalanche effect.
  • Symmetry: The same operations decrypt what was encrypted, keeping it simple.

Features

  • Pure Python, no dependencies
  • Custom authentication tag to detect tampering
  • Designed to teach encryption basics and mathematical reasoning
  • Mathematically inspired — not just a cipher, but a learning tool
  • Includes basic test cases for validation

Try It Out
You can find the project here:
github.com/ArminMemar/CantorCipher
It includes:

  • cantor_cipher.py: the encryption/decryption implementation
  • test_cantor_cipher.py: basic tests
  • README.md: everything explained clearly

All you need is Python 3.

What’s Next?
CantorCipher was just the beginning of my journey into cryptography. I plan to keep exploring how mathematics can power secure communication.

About Me
I’m a high school graduate who loves math, programming, and making new things. I’m exploring cryptography and computational theory through personal projects like CantorCipher.

Final Thoughts
I built CantorCipher because I love math, code, and turning ideas into experiments.

  • If You Like This:
  • Star CantorCipher on GitHub
  • Comment or suggest improvements
  • Share this post with anyone interested in crypto, math, or original ideas

Thanks for reading!


This content originally appeared on DEV Community and was authored by Armin Memar