fork(2) download
  1. <?php
  2. function encrypt($plain, $cipher, $text) {
  3. $plain = $plain . strtoupper($plain);
  4. $cipher = $cipher . strtoupper($cipher);
  5.  
  6. $newText = '';
  7. for($i=0; $i<strlen($text); $i++) {
  8. $c = $text[$i];
  9. $index = strrpos($plain, $c);
  10. if($index && $index < strlen($cipher)) {
  11. $newText = $newText . $cipher[$index];
  12. } else {
  13. $newText = $newText . $c;
  14. }
  15. }
  16. return $newText;
  17. }
  18.  
  19. $plainAlphabet = "abcdefghijklmnopqrstuvwxyz";
  20. $cipherAlphabet = "zyxwvutsrqponmlkjihgfedcba";
  21. $text = "Some sensitive text that only humans must be able to read";
  22.  
  23. $encodedText = encrypt($plainAlphabet, $cipherAlphabet, $text);
  24. echo $encodedText;
  25.  
Success #stdin #stdout 0.02s 24448KB
stdin
Standard input is empty
stdout
Hlnv hvmhrgrev gvcg gsag lmob sfnamh nfhg yv ayov gl ivaw