# ClassicCiphers.jl - A Julia Package for Classical Cryptography

**URL:** <https://discourse.julialang.org/t/classicciphers-jl-a-julia-package-for-classical-cryptography/123564>\
**Category:** General Usage\
**Tags:** cryptography\
**Created:** [December 7, 2024, 12:21pm UTC](https://discourse.julialang.org/t/classicciphers-jl-a-julia-package-for-classical-cryptography/123564 "2024-12-07T12:21:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![scelles](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/scelles/32/220408_2.png) [@scelles](https://discourse.julialang.org/u/scelles)\
**Post date:** [December 7, 2024, 12:21pm UTC](https://discourse.julialang.org/t/classicciphers-jl-a-julia-package-for-classical-cryptography/123564/1 "2024-12-07T12:21:05Z")

</div>

Hi Julia community!

I’m excited to share a new package I’ve been working on: [ClassicCiphers.jl](https://github.com/s-celles/ClassicCiphers.jl). This package was inspired by my experience solving some introduction cryptography challenges on [Hackropole](https://hackropole.fr), a French CTF platform by ANSSI and some other beginners CTF about cryptography.

## Package Overview

ClassicCiphers.jl provides implementations of classical cryptographic ciphers with a focus on:

- Clean, idiomatic Julia code
- Flexible configuration options
- Educational value for learning about historical cryptography
- Useful tools for CTF challenges and cryptography education

## Features

### Supported Ciphers

- Caesar Cipher (with configurable shift)
- ROT13 (special case of Caesar with shift=13)
- Affine cipher
- XOR cipher
- General Substitution Cipher
- Vigenère Cipher
- Vernam Cipher

### Key Features

- Configurable alphabet handling
- Case sensitivity options
- Case preservation modes
- Custom symbol handling
- Built-in cipher inversion (encryption/decryption)

## Usage Examples

### Basic Caesar Cipher

```julia
using ClassicCiphers

# Create a Caesar cipher with default shift (3)
cipher = CaesarCipher()
plaintext = "HELLO"
ciphertext = cipher(plaintext) # Returns "KHOOR"

# Decrypt using inverse cipher
decipher = inv(cipher)
recovered_plaintext = decipher(ciphertext) # Returns "HELLO"

# Custom shift value
cipher = CaesarCipher(shift=5)

```

### Vigenère Cipher with Custom Settings

```julia
# Encryption with a keyword
cipher = VigenereCipher("SECRET")
plaintext = "HELLO WORLD"
ciphertext = cipher(plaintext) # Returns "ZINCS PGVNU"

# Decryption
decipher = inv(cipher)
recovered_plaintext = decipher(ciphertext) # Returns "HELLO WORLD"

```

### Customizable Behavior

```julia
# Configure case sensitivity and symbol handling
params = AlphabetParameters(
    case_sensitivity=CASE_SENSITIVE,
    output_case_mode=DEFAULT_CASE,
    unknown_symbol_handling=REPLACE_SYMBOL
)

cipher = CaesarCipher(shift=5, alphabet_params=params)

```

## Unique Features

1. **Trait-based Design** : The package uses Julia’s type system to handle different aspects of cipher behavior:

2. **Consistent API** : All ciphers follow the same pattern:

3. **Educational Value** : Clear implementations make it easy to understand how classical ciphers work

## Feedback Welcome!

I’d love to hear from the community about:

- Additional cipher implementations you’d like to see (modern ciphers are out of the scope of this package)
- Feature suggestions
- Use cases in education or CTF challenges
- Code improvements and optimizations

## Future Plans

- Add more classical ciphers (Playfair, Hill cipher, etc.)
- Implement cipher analysis tools (maybe in an other package)
- Add visualization helpers for educational purposes
- Create documentation with interactive examples

## Get Started

```julia
using Pkg
Pkg.add(url="https://github.com/s-celles/ClassicCiphers.jl")

```

Looking forward to your feedback and contributions!

Best regards

PS : I’m also open to transfer ownership to [JuliaCrypto · GitHub](https://github.com/JuliaCrypto)  
Pinging @staticfloat @StefanKarpinski @ViralBShah @sloede @oxinabox @aminya

PS2 : Doc is now available at [Home · ClassicCiphers.jl](https://s-celles.github.io/ClassicCiphers.jl/dev/)

---

<div class="post-metadata">

**Author:** ![StevenSiew](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevensiew/32/218393_2.png) [@StevenSiew](https://discourse.julialang.org/u/StevenSiew)\
**Post date:** [December 7, 2024, 11:15pm UTC](https://discourse.julialang.org/t/classicciphers-jl-a-julia-package-for-classical-cryptography/123564/2 "2024-12-07T23:15:24Z")

</div>

Thank you for your module.

Could you please include some tutorial for your module I find the documentation hard to follow. It looked like one of those “The documentation is in the source code” type of module.

---

<div class="post-metadata">

**Author:** ![StevenSiew](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevensiew/32/218393_2.png) [@StevenSiew](https://discourse.julialang.org/u/StevenSiew)\
**Post date:** [December 7, 2024, 11:34pm UTC](https://discourse.julialang.org/t/classicciphers-jl-a-julia-package-for-classical-cryptography/123564/3 "2024-12-07T23:34:20Z")

</div>

While you are at it, please show us how to solve this famous ciphertext.

```julia
julia> ciphertext_goldbug
"GBXXFBIGDDOLKEMNODEXHDEXDKMIOLKEMFMUOIDDMGKZXWKJXLMFMBWMMDGLFKEOWKMMLYOLTKMDLXWKEMGDKGLFNJLXWKEYGOLNWGLCEDMUMLKEIOYNMGDKDOFMDEXXKZWXYKEMIMZKMJMXZKEMFMGKEDEMGFGNMMIOLMZWXYKEMKWMMKEWXTBEKEMDEXKZOZKJZMMKXTK"

```

---

<div class="post-metadata">

**Author:** ![scelles](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/scelles/32/220408_2.png) [@scelles](https://discourse.julialang.org/u/scelles)\
**Post date:** [December 8, 2024, 7:32am UTC](https://discourse.julialang.org/t/classicciphers-jl-a-julia-package-for-classical-cryptography/123564/4 "2024-12-08T07:32:08Z")

</div>

Hi @StevenSiew,

Thank you for your interest in ClassicCiphers.jl! You make a fair point about the documentation. Let me clarify the scope and provide some basic examples.

## Scope Clarification

ClassicCiphers.jl is focused solely on implementing classical cipher methods for **encryption and decryption** when you know the key. It’s not designed for cryptanalysis (breaking ciphers or analyzing encrypted text without the key).

## Quick Tutorial

Documentation is not yet published on Github Pages but can be found at

> <https://github.com/s-celles/ClassicCiphers.jl/blob/main/docs/src/index.md>

and build locally using

```
julia --project=docs/. docs/make.jl

```

## Contributing

If you’d like to help improve the documentation, contributions are very welcome! The package could benefit from:

- More examples
- Better organization of docstrings
- Tutorial notebooks
- A comprehensive README

Regarding the Goldbug ciphertext: Since this package is focused on implementing cipher methods rather than breaking them, it wouldn’t be appropriate for analyzing unknown ciphertexts. For cryptanalysis challenges, you might want to look into specialized tools or packages designed for cipher breaking.

Let me know if you have any other questions about using the implemented cipher methods!

PS : an interesting article can be found on french Wikipedia [Cryptologie dans Le Scarabée d'or — Wikipédia](https://fr.wikipedia.org/wiki/Cryptologie_dans_Le_Scarab%C3%A9e_d%27or)

 ![image](https://global.discourse-cdn.com/julialang/original/3X/e/e/eebba8a8f0123f8fc61ae8e74f78441e35b1e5bc.png)
