Ejemplo n.º 1
0
<?php

function xor_bytes($bina, $binb)
{
    $bin = "";
    $x = 8;
    while ($x) {
        if ($bina[$x - 1] xor $binb[$x - 1]) {
            $bin = 1 . $bin;
        } else {
            $bin = 0 . $bin;
        }
        $x--;
    }
    return $bin;
}
echo xor_bytes("10110000", "10010000");
Ejemplo n.º 2
0
function create_response($xor, $req)
{
    $req = xor_bytes($xor, $req);
    $pkt = pack("N", PACKET_TYPE_RESPONSE);
    $method_tlv = packet_get_tlv($req, TLV_TYPE_METHOD);
    my_print("method is {$method_tlv['value']}");
    packet_add_tlv($pkt, $method_tlv);
    $reqid_tlv = packet_get_tlv($req, TLV_TYPE_REQUEST_ID);
    packet_add_tlv($pkt, $reqid_tlv);
    if (is_callable($method_tlv['value'])) {
        $result = $method_tlv['value']($req, $pkt);
    } else {
        my_print("Got a request for something I don't know how to handle (" . $method_tlv['value'] . "), returning failure");
        $result = ERROR_FAILURE;
    }
    packet_add_tlv($pkt, create_tlv(TLV_TYPE_RESULT, $result));
    # Add the length to the beginning of the packet
    $pkt = pack("N", strlen($pkt) + 4) . $pkt;
    return $pkt;
}
Ejemplo n.º 3
0
//echo($argv[0]."\n");
//$code = $argv[1];
//$message = implode("", file($argv[2]));
$message = "&.(\fh(-fKH-)!F\r\ng%«ÍH\$,7\r\nY";
$code = "gfgFHJghGjhghjfVHGhjGhjGvvXfgdTGfHgHfgFhfVBGcftDtFzdfdgfgf6ztFzF";
//Message to bin array:
$i = 0;
$message_bin = "";
while ($i < strlen($message)) {
    $message_bin = $message_bin . bin_trim(base_convert(ord($message[$i]), 10, 2)) . "\n ";
    $i++;
}
//echo ($message_bin."\n\n"); //Debug
$message_bin = explode(" ", $message_bin);
//Encode:
$i = 0;
$y = 0;
while ($i < strlen($message)) {
    $char = $message_bin[$i];
    $cchar = bin_trim(base_convert(ord($code[$y]), 10, 2));
    //echo($code[$y]); //Debug
    //echo($cchar."\n"); //Debug
    //echo($char); //Debug
    $message[$i] = chr(base_convert(xor_bytes($char, $cchar), 2, 10));
    $y++;
    if ($y >= strlen($code)) {
        $y = 0;
    }
    $i++;
}
echo $message;