$rowIndex) { $lengths[$rowIndex]++; } if ($balance > ($rails + ($rails - $rowIndex) - 2)) { $lengths[$rowIndex]++; } $strings[] = substr($cipherMessage, $totalLengths, $lengths[$rowIndex]); $totalLengths += $lengths[$rowIndex]; } //convert row of characters to plain message $plainText = ''; while (strlen($plainText) < $textLength) { for ($charIndex = 0; $charIndex < $position; $charIndex++) { if (isset($strings[$charIndex])) { $index = $charIndex; } else { $index = $position - $charIndex; } $plainText .= substr($strings[$index], 0, 1); $strings[$index] = substr($strings[$index], 1); } } return $plainText; }