Skip to content

Conversation

@AliAlimohammadi
Copy link
Contributor

Description

This PR adds a Hill Cipher implementation to the ciphers module.

About Hill Cipher

The Hill Cipher is a polygraphic substitution cipher based on linear algebra. It encrypts blocks of letters using matrix multiplication modulo 36 (for alphanumeric characters A-Z, 0-9).

Implementation Details

  • Pure Rust implementation with zero external dependencies
  • All matrix operations (determinant, inverse, cofactor) implemented manually
  • Supports any $N \times N$ key matrix
  • Validates that key matrix determinant is coprime with 36
  • Comprehensive test coverage

Testing

All tests pass:

cargo test hill_cipher

Example Usage

use ciphers::hill_cipher::HillCipher;

let key = vec![vec![2, 5], vec![1, 6]];
let cipher = HillCipher::new(key).unwrap();

let encrypted = cipher.encrypt("HELLO");
// Returns: "85FF00"

let decrypted = cipher.decrypt(&encrypted);
// Returns: "HELLOO" (with padding)

References

@AliAlimohammadi
Copy link
Contributor Author

@siriak, this is ready to be merged.

@AliAlimohammadi
Copy link
Contributor Author

The issue is not related to my changes.

@siriak siriak merged commit d850c9c into TheAlgorithms:master Jan 23, 2026
7 of 8 checks passed
@codecov-commenter
Copy link

Codecov Report

❌ Patch coverage is 98.71795% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 96.11%. Comparing base (a6f9ffd) to head (666c99b).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
src/ciphers/hill_cipher.rs 98.71% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1006      +/-   ##
==========================================
+ Coverage   96.09%   96.11%   +0.01%     
==========================================
  Files         375      376       +1     
  Lines       26674    26908     +234     
==========================================
+ Hits        25632    25862     +230     
- Misses       1042     1046       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants