Untitled

From Snotlepel, 2 Years ago, written in Plain Text, viewed 115 times.
URL https://paste.bugabuse.net/view/1741bd7e Embed
Download Paste or View Raw
  1. <?php
  2.  
  3. function encode($string, $alphabet)
  4. {
  5.  foreach(str_split(strtolower($string)) as $char)
  6.  {
  7.   @$resp .= $alphabet[$char];
  8.  }
  9.  
  10.  return $resp;
  11. }
  12.  
  13. function decode($string, $alphabet)
  14. {
  15.  foreach(str_split(strtolower($string)) as $char)
  16.  {
  17.   foreach($alphabet as $c => $r)
  18.   {
  19.    if ($char == $r) @$resp .= $c;
  20.   }
  21.  }
  22.  
  23.  return $resp;
  24. }
  25.  
  26. $a = range('a', 'z', 2);
  27.  
  28. foreach(range('a', 'z') as $char)
  29. {
  30.  if (!in_array($char, $a)) $a[] = $char;
  31. }
  32.  
  33.  
  34. for ($c=0; $c<=25; $c++)
  35. {
  36.  @$alphabet[range('a', 'z')[$c]] = $a[$c];
  37. }
  38.  
  39. $alphabet[' '] = ' ';
  40.  
  41. echo encode('my name is dan', $alphabet) . "\n"; // yx bayi ql gab
  42. echo decode('yx bayi ql gab', $alphabet);

Reply to "Untitled"

Here you can reply to the paste above