Advertisement
yacked2

[PHP]-BinarnoDekodiranje

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