feat: add base32 cipher implementation #991
Merged
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 an implementation of Base32 encoding and decoding to the ciphers module. Base32 is a binary-to-text encoding scheme that represents binary data using 32 ASCII characters (A-Z and 2-7), following RFC 4648 specifications.
Implementation Details
The implementation provides two public functions:
1.
base32_encode(data: &[u8]) -> Vec<u8>2.
base32_decode(data: &[u8]) -> Result<Vec<u8>, String>Resultwith descriptive error messagesAlgorithm Details
write!macro instead offormat!for better performanceUse Cases
Base32 is commonly used when:
Changes Made
src/ciphers/base32.rswith complete implementationsrc/ciphers/mod.rsto include and export the new modulewrite!instead offormat!)Type of Change
Test Coverage
b"Hello World!"→b"JBSWY3DPEBLW64TMMQQQ===="b"JBSWY3DPEBLW64TMMQQQ====""→b"Hello World!"b"123456"→b"GEZDGNBVGY======"b"some long complex string"→b"ONXW2ZJANRXW4ZZAMNXW24DMMV4CA43UOJUW4ZY="Examples
Performance Optimizations
write!macro instead offormat!in loops (avoids intermediate allocations)is_multiple_of()for clearer intentCode Quality
Checklist
cargo fmtcargo clippy