Skip to content

Validate Rail Fence cipher rail counts - #110

Closed
krotname wants to merge 1 commit into
mainfrom
codex/fix-railfencecipher-bugs-and-incomplete-decode
Closed

Validate Rail Fence cipher rail counts#110
krotname wants to merge 1 commit into
mainfrom
codex/fix-railfencecipher-bugs-and-incomplete-decode

Conversation

@krotname

@krotname krotname commented Aug 1, 2026

Copy link
Copy Markdown
Owner

Motivation

  • Prevent runtime crashes and undefined behavior when callers pass invalid rail counts to the Rail Fence cipher routines by failing fast with a clear error.
  • Ensure both encode and decode respect the kata precondition that rails >= 2 and provide regression coverage for invalid inputs.

Description

  • Added a shared validateRailCount(int) helper that throws IllegalArgumentException when the rail count is less than 2 and invoked it from both encode and decode in src/main/java/kyu3/RailFenceCipher.java.
  • Preserved existing traversal and reconstruction logic while avoiding prior arithmetic/null/indexing faults for invalid n values.
  • Added a parameterized test shouldRejectInvalidRailCounts and invalidRailCounts test data to src/test/java/kyu3/RailFenceCipherTest.java and imported assertThrows to verify negative, zero, and single-rail inputs are rejected.

Testing

  • Ran the unit tests with mvn -q -Dtest=RailFenceCipherTest test and the new tests passed.
  • Ran the full Maven verification with mvn -q verify and the build completed successfully including test and verification phases.
  • Existing round-trip and example tests in RailFenceCipherTest continue to pass after the changes.

Codex Task

@krotname

krotname commented Aug 1, 2026

Copy link
Copy Markdown
Owner Author

Superseded by the validated combined merge in #115: #115

@krotname krotname closed this Aug 1, 2026
@krotname
krotname deleted the codex/fix-railfencecipher-bugs-and-incomplete-decode branch August 1, 2026 02:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant