Skip to content

fix(railfence): size zigzag by characters, not bytes - #1037

Merged
bee-san merged 2 commits into
bee-san:masterfrom
Saadanjum0:fix/railfence-multibyte
Oct 5, 2026
Merged

bee-san merged 2 commits into
bee-san:masterfrom
Saadanjum0:fix/railfence-multibyte

Conversation

@Saadanjum0

Copy link
Copy Markdown
Contributor

Problem

Rail fence decoding of text containing multi-byte characters returns wrongly ordered output. E.g. railfence_decoder("ÄCEBDF", 2, 0) gave ÄDCFEB instead of ÄBCDEF.

Cause

railfence_decoder generated text.len() zigzag positions (bytes) but pairs them with text.chars(). The extra positions shift which characters land on which rail.

Fix

Use text.chars().count().

Testing

Added railfence_decoder_counts_chars_not_bytes; it fails before the change and passes after. cargo test --lib railfence passes.

Saadanjum0 and others added 2 commits October 1, 2026 16:23
The decoder took text.len() (bytes) positions from the zigzag but zipped them with chars(), so any input with a multi-byte character was assigned the wrong rail positions and decoded to garbled text.
Keep master's counting-sort decoder, sized by characters as this PR
intends, and update the reference test to the character-based version.
@bee-san
bee-san merged commit 0e135fc into bee-san:master Oct 5, 2026
8 checks passed
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.

2 participants