1. <?php
  2.  
  3. class PCK {
  4.  
  5. var $key;
  6.  
  7.  function PCK() {
  8.  
  9. $this->key = $this->pck_key();
  10.  
  11. }
  12.  
  13.  function pck_key() {
  14.  
  15. $rArr = array();
  16. $temp = array();
  17.  
  18. for ($x=0;$x<128;$x++) { $array[] = chr($x);}
  19.  
  20. while(count($rArr)<128) {
  21.  
  22. $number = rand(0,127);
  23.  
  24. if (!in_array($number,$rArr)) { $rArr[] = $number; }
  25.  
  26. }
  27.  
  28. for($x=0;$x<128;$x++) { $temp[$rArr[$x]] = $array[$x]; }
  29.  
  30. return $temp;
  31.  
  32.  }
  33.  
  34.  function pck_code($string) {
  35.  
  36. // ord() --> return ASCII value of character
  37. $long = strlen($string);
  38. $newstring = '';
  39.  
  40. for ($m=0;$m<$long;$m++) {
  41.  
  42. $newstring .= $this->key[ord($string[$m])];
  43.  
  44. }
  45.  
  46. return $newstring;
  47.  
  48.  }
  49.  
  50.  function pck_decode($string) {
  51.  
  52. $long = strlen($string);
  53. $oldstring = '';
  54.  
  55. for ($m=0;$m<$long;$m++) {
  56.  
  57. $a = array_keys($this->key,$string[$m]);
  58.  
  59. $oldstring .= chr($a[0]); 
  60.  
  61. }
  62.  
  63. return $oldstring;
  64.  
  65.  }
  66. }
  67. ?>


Wywolanie:
  1. <?php
  2.  
  3. $information = "Bla bla xx skdjsalkdjsla jasld ad ";
  4.  
  5. $PCK = new PCK();
  6.  
  7. echo $string = $PCK->pck_code($information);
  8.  
  9. echo '<br><br>';
  10.  
  11. echo $PCK->pck_decode($string);
  12. ?>


Funckja generuje unikatowy klucz w postaci pomieszanej tablicy kodow ASCII, nastepnie dziala jak prosta maszyna szyfrujaca (enigma?) ktora dostaje za kazdym razem inny klucz wg, ktorego podmienia znaki, i tylko wlasciciel odpowiedniego klucza jest w stanie w danym momencie odczytac tresc wiadomosci...