Advertisement
yacked2

[PHP]-BinarnoKodiranje

Apr 4th, 2013
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.79 KB | None | 0 0
  1. <?php
  2.  
  3. $niz='HELLO';
  4. $key='DAVID';
  5.  
  6. $key = str_split($key);
  7. $niz = str_split($niz);
  8.  
  9. foreach($niz as $index => $element)
  10. {
  11.     $bin = decbin(ord($element));
  12.     $binar[] = $bin;
  13. }
  14. $niz = implode('',$binar);
  15.  
  16. foreach($key as $index => $element)
  17. {
  18.     $bin = decbin(ord($element));
  19.     $kjuc[] = $bin;
  20. }
  21. $key = implode('',$kjuc);
  22.  
  23. $in = str_split($niz);
  24. $out = str_split($key);
  25.  
  26. foreach($in as $index => $element)
  27. {
  28.    
  29.     while ($index >= count($out))
  30.     {
  31.         $index = $index -count($out);
  32.     }
  33.     //index
  34.     if($element == $out[$index])
  35.     {
  36.         $output[] = '0';
  37.     }
  38.     else
  39.     {
  40.         $output[] = '1';
  41.     }
  42. }
  43.  
  44. $izpis= (array_chunk($output, 7));
  45.  
  46. foreach($izpis as $index => $element)
  47. {
  48.     $konec[] = implode('',$element);
  49. }
  50.  
  51. foreach($konec as $index => $element)
  52. {
  53.     echo $element.' ';
  54. }
  55.  
  56. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement