Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bin/auto-sync.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ pig-latin
protein-translation
proverb
queen-attack
rail-fence-cipher
raindrops
reverse-string
rna-transcription
Expand Down
10 changes: 4 additions & 6 deletions exercises/practice/rail-fence-cipher/.docs/instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@

Implement encoding and decoding for the rail fence cipher.

The Rail Fence cipher is a form of transposition cipher that gets its name from
the way in which it's encoded. It was already used by the ancient Greeks.
The Rail Fence cipher is a form of transposition cipher that gets its name from the way in which it's encoded.
It was already used by the ancient Greeks.

In the Rail Fence cipher, the message is written downwards on successive "rails"
of an imaginary fence, then moving up when we get to the bottom (like a zig-zag).
In the Rail Fence cipher, the message is written downwards on successive "rails" of an imaginary fence, then moving up when we get to the bottom (like a zig-zag).
Finally the message is then read off in rows.

For example, using three "rails" and the message "WE ARE DISCOVERED FLEE AT ONCE",
the cipherer writes out:
For example, using three "rails" and the message "WE ARE DISCOVERED FLEE AT ONCE", the cipherer writes out:

```text
W . . . E . . . C . . . R . . . L . . . T . . . E
Expand Down
3 changes: 2 additions & 1 deletion exercises/practice/rail-fence-cipher/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"arueckauer",
"kunicmarko20",
"kytrinyx",
"yisraeldov"
"yisraeldov",
"A-O-Emmanuel"
],
"files": {
"solution": [
Expand Down
22 changes: 0 additions & 22 deletions exercises/practice/rail-fence-cipher/.meta/example.php
Original file line number Diff line number Diff line change
@@ -1,27 +1,5 @@
<?php

/*
* By adding type hints and enabling strict type checking, code can become
* easier to read, self-documenting and reduce the number of potential bugs.
* By default, type declarations are non-strict, which means they will attempt
* to change the original type to match the type specified by the
* type-declaration.
*
* In other words, if you pass a string to a function requiring a float,
* it will attempt to convert the string value to a float.
*
* To enable strict mode, a single declare directive must be placed at the top
* of the file.
* This means that the strictness of typing is configured on a per-file basis.
* This directive not only affects the type declarations of parameters, but also
* a function's return type.
*
* For more info review the Concept on strict type checking in the PHP track
* <link>.
*
* To disable strict typing, comment out the directive below.
*/

declare(strict_types=1);

function encode($plainMessage, $rails)
Expand Down
43 changes: 15 additions & 28 deletions exercises/practice/rail-fence-cipher/RailFenceCipherTest.php
Original file line number Diff line number Diff line change
@@ -1,30 +1,9 @@
<?php

/*
* By adding type hints and enabling strict type checking, code can become
* easier to read, self-documenting and reduce the number of potential bugs.
* By default, type declarations are non-strict, which means they will attempt
* to change the original type to match the type specified by the
* type-declaration.
*
* In other words, if you pass a string to a function requiring a float,
* it will attempt to convert the string value to a float.
*
* To enable strict mode, a single declare directive must be placed at the top
* of the file.
* This means that the strictness of typing is configured on a per-file basis.
* This directive not only affects the type declarations of parameters, but also
* a function's return type.
*
* For more info review the Concept on strict type checking in the PHP track
* <link>.
*
* To disable strict typing, comment out the directive below.
*/

declare(strict_types=1);

use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Attributes\TestDox;

class RailFenceCipherTest extends TestCase
{
Expand All @@ -34,18 +13,21 @@ public static function setUpBeforeClass(): void
}

/**
* Test encode with two rails.
* uuid 46dc5c50-5538-401d-93a5-41102680d068
*/
#[TestDox('encode with two rails')]
public function testEncodeWithTwoRails(): void
{
$plainText = "XOXOXOXOXOXOXOXOXO";
$rails = 2;
$expected = "XXXXXXXXXOOOOOOOOO";
$this->assertEquals($expected, encode($plainText, $rails));
}

/**
* Test encode with three rails.
* uuid 25691697-fbd8-4278-8c38-b84068b7bc29
*/
#[TestDox('encode with three rails')]
public function testEncodeWithThreeRails(): void
{
$plainText = "WEAREDISCOVEREDFLEEATONCE";
Expand All @@ -55,8 +37,9 @@ public function testEncodeWithThreeRails(): void
}

/**
* Test encode with ending in the middle.
* uuid 384f0fea-1442-4f1a-a7c4-5cbc2044002c
*/
#[TestDox('encode with ending in the middle')]
public function testEncodeWithEndingInTheMiddle(): void
{
$plainText = "EXERCISES";
Expand All @@ -66,18 +49,21 @@ public function testEncodeWithEndingInTheMiddle(): void
}

/**
* Test decode with three rails.
* uuid cd525b17-ec34-45ef-8f0e-4f27c24a7127
*/
#[TestDox('decode with three rails')]
public function testDecodeWithThreeRails(): void
{
$encryptedText = "TEITELHDVLSNHDTISEIIEA";
$rails = 3;
$expected = "THEDEVILISINTHEDETAILS";
$this->assertEquals($expected, decode($encryptedText, $rails));
}

/**
* Test decode with five rails.
* uuid dd7b4a98-1a52-4e5c-9499-cbb117833507
*/
#[TestDox('decode with five rails')]
public function testDecodeWithFiveRails(): void
{
$encryptedText = "EIEXMSMESAORIWSCE";
Expand All @@ -87,8 +73,9 @@ public function testDecodeWithFiveRails(): void
}

/**
* Test decode with six rails.
* uuid 93e1ecf4-fac9-45d9-9cd2-591f47d3b8d3
*/
#[TestDox('decode with six rails')]
public function testDecodeWithSixRails(): void
{
$encryptedText = "133714114238148966225439541018335470986172518171757571896261";
Expand Down
Loading