Letter Shift with PHP
<p>I am trying to create a PHP function that Ciphers a string using a letter shift down or up the alphabet using a value of their choice.</p>

<p>This is what I have so far:</p>

<pre><code>function encrypt($in, $n) {
    $in = strtolower($in);
    $let = array("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z");
    $num = array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25");
    $negnum = array("-26", "-25", "-24", "-23", "-22", "-21", "-20", "-19", "-18", "-17", "-16", "-15", "-14", "-13", "-12", "-11", "-10", "-9", "-8", "-7", "-6", "-5", "-4", "-3", "-2", "-1");
    $nums = str_replace($let, $num, $in);
    $temp = str_split($nums, 1);
    foreach($temp as &amp;$v) {
        $v = ($v + $n);
        if($v == 0 or $v &gt; 0){
            $v = str_replace($num, $let, $v);
        } else {
            $v = str_replace($negnum, $let, $v);
        }   
    }
    return implode('', $temp);
}

echo encrypt('EPPEABBOADBFTBS', '-3');
</code></pre>

<p>In it's current state the function is really not working - outputting strings that don't fit the value and also repeating letters of the string.</p>

<p>Am I going around this in the right way?</p>

<p>Please let me know,</p>

<p>Brad</p>
