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.

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.

1 participant