feat: add Gronsfeld cipher implementation#1045
Open
qsrbit wants to merge 1 commit into
Open
Conversation
Implements encrypt and decrypt functions for the Gronsfeld cipher, a Vigenère variant where the key is a digit sequence (0-9). Includes 20 tests covering key validation, case preservation, alphabet wrap-around, and round-trip correctness.
Author
|
@siriak Hi, can you take a look at this PR in your convenience time. Thank you |
There was a problem hiding this comment.
Pull request overview
Adds a new Gronsfeld cipher implementation to the ciphers module, exposing encrypt/decrypt APIs and accompanying unit tests.
Changes:
- Introduce
gronsfeld_encrypt/gronsfeld_decryptwith key validation and ASCII letter shifting. - Add unit tests for key validation, case preservation, wrap-around, and round-trip behavior.
- Wire the new module into
src/ciphers/mod.rsfor compilation and public re-export.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/ciphers/mod.rs | Registers the new gronsfeld module and re-exports its public functions. |
| src/ciphers/gronsfeld.rs | Implements Gronsfeld encrypt/decrypt logic plus unit tests. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+15
to
+22
| fn validate_key(key: &str) -> Result<Vec<u8>, &'static str> { | ||
| if key.is_empty() { | ||
| return Err(ERR_EMPTY_KEY); | ||
| } | ||
| key.chars() | ||
| .map(|c| c.to_digit(10).map(|d| d as u8).ok_or(ERR_INVALID_KEY)) | ||
| .collect() | ||
| } |
|
|
||
| #[test] | ||
| fn roundtrip_with_unicode_passthrough() { | ||
| let plain = "Rust 2024"; |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1045 +/- ##
==========================================
+ Coverage 95.82% 95.84% +0.01%
==========================================
Files 393 394 +1
Lines 29971 30081 +110
==========================================
+ Hits 28721 28830 +109
- Misses 1250 1251 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
siriak
requested changes
Jun 15, 2026
siriak
left a comment
Member
There was a problem hiding this comment.
Please review Copilot's comments, everything else looks good
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR adds a Gronsfeld Cipher implementation to the ciphers module.
About Gronsfeld Cipher
The Gronsfeld cipher, a Vigenère variant where the key is a digit sequence (0-9). Includes 20 tests covering key validation, case preservation, alphabet wrap-around, and round-trip correctness.
Implementation Details
The implementation provides two public functions:
gronsfeld_encrypt(text: &str, key: &str) -> Result<String, &'static str>gronsfeld_decrypt(text: &str, key: &str) -> Result<String, &'static str>gronsfeld_encrypt:decrypt(encrypt(text, key), key) == textAlgorithm Details
"31415"or"9876543210"Testing
All tests pass and the codebase is clean:
cargo test gronsfeld cargo fmt --check cargo clippy -- -D warningsTest Coverage
"abc"+"123"="bdf"'z'+ 1 ='a'"Hello, World!"+"5"="Mjqqt, Btwqi!""bdf"+"123"="abc"'a'- 1 ='z'Examples
Checklist
cargo fmtcargo clippy