title: Unable to decrypt my encrypted string in a substitution cipher
body: <p>I am developing my own encryption and decryption algorithms. My encryption function is working fine, but my decryption function is not working properly. The following are my functions:</p>
  
  <pre><code>&lt;?php
  function encrypt($os,$mode=64,$pattern="tyv9xXa2iUEMhZLD6YlF4BOjg8AdJz0nVHKPRTpb5smfQ1WwroIkqcN3eSG7Cu"){
      $ns="";
      for($i=0;$i&lt;strlen($os);$i++){
          $ns.=$pattern[(strpos($pattern,$os[$i])+$mode)%strlen($pattern)];
      }
      return $ns;
  }
  function decrypt($os,$mode=64,$pattern="tyv9xXa2iUEMhZLD6YlF4BOjg8AdJz0nVHKPRTpb5smfQ1WwroIkqcN3eSG7Cu"){
      $ns="";
      for($i=0;$i&lt;strlen($os);$i++){
          $ns.=$pattern[abs(strpos($pattern,$os[$i])-$mode)%strlen($pattern)];
      }
      return $ns;
  }
  echo decrypt(encrypt("abcde"));
  ?&gt;
  </code></pre>
  
  <p>My expected output is: <code>abcde</code></p>
  
  <p>But the output returned is: <code>ejUPa</code></p>