added tips to lamer.bash help
[mirrors/Programs.git] / php / skripty / xor_enc.php
1 <?php
2
3 function bin_trim ($bin) {
4
5 $x = (8 - strlen($bin));
6 $y = "";
7 while($x) {
8 $y = ($y."0");
9 $x--;
10 }
11 return($y.$bin);
12
13 }
14
15 function xor_bytes ($bina, $binb) {
16 $bin = "";
17 $x = 8;
18 while($x) {
19 if ($bina[$x-1] XOR $binb[$x-1])
20 { $bin = ( 1 . $bin ); } else { $bin = ( 0 . $bin ); }
21 $x--;
22 }
23 return $bin;
24 }
25
26 //CODE/////////////////////////////////////////////////////
27
28 $message = "POKUS CISLO JEDNA DVA TRI";
29 $message = ")-#&O&$6(.:E/-:H&#&*H--$.";
30 $message = "message MESSAGE toto je pokus 545446653\9aèøèø\9eøýá ahoj";
31 //$message = "%-\e\14) -g&\ 2\11\10\12\ 23N\1f%\1d\15Z\8b\98\17F\97\83\9d\8eÍÜ\ 4\fÝA×CÔI{¼ªÝÌÛ̸Õe\e\89\15\93";
32 $message = implode("", file("cypher.txt"));
33 $code = "HHhgHGHGkGBCSEvnkJizzáý76øèèýíé09éuáuázáTR54E4E4Ezázùdlmkdsfh-";
34
35 //print "Pocet parametru: " . $argc . "\n";
36 //foreach($argv as $param)
37 // print $param . "\n";
38
39 //if($argc != 3) { die("Usage: xor.php secretcode in.txt > out.txt\n"); }
40
41 //echo($argv[0]."\n");
42 //$code = $argv[1];
43 //$message = implode("", file($argv[2]));
44 $message = "&.(\fh\1c(-fKH-)!F\ 5
45 g%«ÍH$\ 6,7
46 Y";
47 $code = "gfgFHJghGjhghjfVHGhjGhjGvvXfgdTGfHgHfgFhfVBGcftDtFzdfdgfgf6ztFzF";
48
49
50
51 //Message to bin array:
52 $i = 0;
53 $message_bin = "";
54 while($i < strlen($message)) {
55 $message_bin = ($message_bin . bin_trim(base_convert(ord($message[$i]),10,2)). "\n " );
56 $i++;
57 }
58 //echo ($message_bin."\n\n"); //Debug
59
60 $message_bin = explode(" ",$message_bin);
61
62 //Encode:
63 $i = 0;
64 $y = 0;
65 while ($i < strlen($message)) {
66
67 $char = $message_bin[$i];
68 $cchar = bin_trim( base_convert( ord($code[$y]), 10, 2) );
69
70 //echo($code[$y]); //Debug
71 //echo($cchar."\n"); //Debug
72 //echo($char); //Debug
73
74 $message[$i] = chr( base_convert(xor_bytes($char, $cchar),2,10 ));
75
76 $y++;
77 if ($y >= strlen($code)) { $y = 0; }
78 $i++;
79
80 }
81
82 echo($message);
83
84 ?>
This page took 1.751343 seconds and 4 git commands to generate.