Skip to content

test(cipher): add fuzz testing, unicode support and edge cases for railfence - #813

Open
mazkev wants to merge 1 commit into
TheAlgorithms:masterfrom
mazkev:test/railfence-fuzz-and-unicode
Open

mazkev wants to merge 1 commit into
TheAlgorithms:masterfrom
mazkev:test/railfence-fuzz-and-unicode

Conversation

@mazkev

@mazkev mazkev commented Oct 28, 2026

Copy link
Copy Markdown

Description of Change

Fixes #480

This PR addresses the open issue #480 ("Add FuzzXxx tests to cipher algorithms") by adding fuzz testing to the Rail Fence cipher, alongside fixing Unicode support and edge case handling:

  1. Fuzz Testing (FuzzRailfence):
    • Implemented native Go fuzz test with UTF-8 input validation.
    • Tested through 190,000+ random fuzz iterations without failure.
  2. Full Unicode / Multibyte Support:
    • Refactored Encrypt and Decrypt to operate on []rune rather than raw string byte indices. Multibyte characters (e.g. non-Latin scripts, emojis) are now encrypted and decrypted correctly.
  3. Null Byte Preservation & Optimization:
    • Replaced sparse 2D matrix allocation with dynamic row slices.
    • Eliminates the previous issue where null bytes (\x00) were filtered out and lost during encryption.
  4. Edge Case Safety:
    • Added guards for rails <= 1 or rails >= len(runes) to prevent runtime panics when non-positive rails are provided.

Checklist

  • Added description of change
  • Added file name matches File name guidelines
  • Added tests and example, test must pass
  • Added documentation so that the program is self-explanatory and educational - GoDoc guidelines
  • Relevant documentation/comments is changed or added
  • PR title follows semantic commit guidelines
  • Search previous suggestions before making a new one, as yours may be a duplicate.
  • I acknowledge that all my contributions will be made under the project's license.

Notes: Adds FuzzRailfence, Unicode support, and edge-case safety for rail fence cipher.

…ilfence

- Implements FuzzRailfence as requested in issue TheAlgorithms#480.

- Refactors Encrypt and Decrypt to properly operate on runes, enabling full Unicode support.

- Optimizes Encrypt to append directly to row slices, avoiding 2D sparse matrix allocation and eliminating the bug where null bytes were dropped.

- Adds guards for rails <= 1 in Encrypt and Decrypt to prevent runtime panic on negative or zero rails.

- Adds Unicode and edge cases to TestEncrypt and TestDecrypt.
@codacy-production

Copy link
Copy Markdown

Not up to standards ⛔

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new 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.

Add FuzzXxx tests to cipher algorithms

1 participant