Ejemplo n.º 1
0
Archivo: Code39.php Proyecto: cicb/tpc
 public function draw($checksum = false)
 {
     $unit = $this->unit;
     $x = $this->x;
     $height = $this->height;
     $bw = $this->bw;
     $str = $this->codigo;
     $str = strtoupper($str);
     if ($checksum) {
         $str = $str . checksum($str);
     }
     $str = '*' . $str . '*';
     echo $str;
     $long = (strlen($str) + 3) * 12;
     $width = $bw * $long;
     $text = str_split($str);
     $img = '';
     $img .= "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n";
     $img .= "<svg width='{$width}{$unit}' height='{$height}{$unit}' version='1.1' xmlns='http://www.w3.org/2000/svg'>\n";
     foreach ($text as $char) {
         $img .= $this->drawsymbol($char);
     }
     $img .= '</svg>';
     return $img;
 }
Ejemplo n.º 2
0
Archivo: Code128.php Proyecto: cicb/tpc
function draw($text, $type = 'B', $check = false)
{
    global $unit, $x, $code128, $height, $bw, $fs, $dx, $yt;
    $type = preg_replace('/\\W/', '', $type);
    $type = substr($type, 0, 1);
    $type = strtoupper($type);
    $clong = (strlen($text) + 4) * 11;
    $width = $bw * $clong;
    switch ($type) {
        case 'A':
            $start = $code128[103];
            break;
        case 'B':
            $start = $code128[104];
            break;
        case 'C':
            $start = $code128[105];
            break;
        default:
            $start = $code128[104];
            break;
    }
    $ctext = $start . $text;
    if ($check) {
        $text .= checksum($ctext);
    }
    $text = str_split($text);
    $img = '';
    $img .= "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n";
    $img .= "<svg width='{$width}{$unit}' height='{$height}{$unit}' version='1.1' xmlns='http://www.w3.org/2000/svg'>\n";
    //Draw Guard bar.
    $img .= "<desc>First Guard</desc>\n";
    //StartCode
    $img .= drawchar($start);
    //Begin Content
    foreach ($text as $char) {
        $index = ord($char) - 32;
        $xt = $x + $dx;
        $img .= "<desc>{$char}</desc>\n";
        $img .= drawchar($code128[$index]);
        $img .= "<text x='{$xt}{$unit}' y='{$yt}{$unit}' font-family='Arial' font-size='{$fs}'>{$char}</text>\n";
    }
    //End guard bar.
    $img .= drawchar($code128[106]);
    $img .= '</svg>';
    return $img;
}
}
// fill to 432 with 0x00
while (count($header) < $header_length - 80) {
    $header[] = 0x0;
}
// fill to 512 with 0xcc
while (count($header) < $header_length) {
    $header[] = 0xcc;
}
#####################################################################
#  Assemble output
#####################################################################
$arr = $header;
array_unshift($arr, 'C' . $header_length);
$initstr = call_user_func_array('pack', $arr);
$checktext = $initstr . $body;
array_splice($header, 4, 2, checksum($checktext));
$arr = $header;
array_unshift($arr, 'C' . $header_length);
$initstr = call_user_func_array('pack', $arr);
$out = $initstr . $body;
#####################################################################
#  output
#####################################################################
ob_start();
echo $out;
if (!headers_sent()) {
    header('Content-Type: application/octet-stream');
    header('Content-Length: ' . (int) @ob_get_length());
}
@ob_flush();
Ejemplo n.º 4
0
function patchInfo($filename = '')
{
    //echo __FUNCTION__."($filename)\n";
    $INFO = [];
    //output
    $size = filesize($filename);
    echo "size={$size}\n";
    //$head=[];
    $f = fopen($filename, "r");
    $head = fread($f, 10);
    //sysex header
    $patch = fread($f, 1024);
    //Patch
    $checksum = fread($f, 1);
    //CheckSum
    $f7 = fread($f, 1);
    //F7
    fclose($f);
    // F0 00 00 7E 4B
    for ($i = 0; $i < strlen($head); $i++) {
        $b = $head[$i];
        echo strtoupper(bin2hex($b));
        echo ' ';
    }
    $INFO['device-number'] = ord($head[5]);
    $INFO['bank'] = ord($head[8]);
    $INFO['patch'] = ord($head[9]);
    //echo "\n";
    $PATCH = [];
    for ($i = 0; $i < strlen($patch); $i += 2) {
        $b1 = $patch[$i];
        $b2 = $patch[$i + 1];
        //$value=bindec($b1)+(bindec($b2)*16);
        //echo 'lo:'.strtoupper(bin2hex($b1));
        ///echo ' - hi:'.strtoupper(bin2hex($b2));
        //echo "\n";
        $low = ord($b1);
        $high = ord($b2);
        $value = $low + $high * 16;
        //echo $value;echo ' ';
        $PATCH[] = $value;
    }
    //echo "\n";
    //show patch as hex
    /*
    for($i=0;$i<count($PATCH);$i++){
    	$b=$PATCH[$i];
    	echo chr($b);
    }
    */
    $name = [];
    for ($i = 0; $i < 16; $i++) {
        $name[] = chr($PATCH[$i]);
    }
    $INFO['name'] = trim(implode('', $name));
    $INFO['engine'] = ord($PATCH[0x10]) & 0xf;
    //0=Lead, 1=Bassline, 2=Drum, 3=Multi
    $INFO['extSwitch'] = $PATCH[0x14];
    // | [7:0] External Switches on/off
    $KNOBS = [];
    for ($i = 0; $i < 8; $i++) {
        /*
             | Knob #1 (Modulation Wheel)
        		0x018 | [7:0] Parameter Assignment #1
        		0x019 | [7:0] Parameter Assignment #2
        		0x01a | [7:0] Initial Value
        		0x01b | [7:0] Min. Value
        		0x01c | [7:0] Max. Value
        */
        $addr = 0x18 + $i * 5;
        $P1 = $PATCH[$addr];
        $P2 = $PATCH[$addr + 1];
        $INI = $PATCH[$addr + 2];
        $MIN = $PATCH[$addr + 3];
        $MAX = $PATCH[$addr + 4];
        $KNOBS[] = [$P1, $P2, $INI, $MIN, $MAX];
    }
    $INFO['knobs'] = $KNOBS;
    //print_r($KNOBS);
    //echo "engine=".$engine;echo "\n";//lead=48, bassline=49, drum=50 multi=51 ()
    //echo "engine=".ord($engine);echo "\n";//lead=48, bassline=49, drum=50 multi=51 ()
    $INFO["checksum"] = bin2hex($checksum);
    $INFO["checksum_calc"] = checksum($patch);
    //echo "f7=".bin2hex($f7);echo "\n";
    $INFO['f7'] = bin2hex($f7);
    return $INFO;
}
Ejemplo n.º 5
0
        }
        if (isset($off) and isset($on) and $off < $on) {
            $CODE = Null;
            $CODE1 = Null;
        }
        break;
    default:
        $CODE = Null;
}
$conf = Null;
if (!is_null($CODE)) {
    $CODE = '88' . $CODE . checksum($CODE);
    $conf .= "          MY_COMMAND               0x" . strtoupper($CODE) . "\n";
}
if (!is_null($CODE1)) {
    $CODE1 = '88' . $CODE1 . checksum($CODE1);
    $conf .= "          MY_COMMAND1              0x" . strtoupper($CODE1) . "\n";
}
if (!is_null($conf)) {
    $conf = file_get_contents("/user1/lircd/lircd.conf1") . $conf;
    $conf .= file_get_contents("/user1/lircd/lircd.conf2");
    file_put_contents("/user1/lircd/lircd.conf", $conf);
    system("sudo /usr/bin/pkill -HUP lircd");
    if (!is_null($CODE)) {
        system("/usr/bin/irsend SEND_ONCE lgac MY_COMMAND");
        echo "sending MY_COMMAND " . $CODE . "<br>";
    }
    if (!is_null($CODE1)) {
        sleep(2);
        system("/usr/bin/irsend SEND_ONCE lgac MY_COMMAND1");
        echo "sending MY_COMMAND1 " . $CODE1 . "<br>";
Ejemplo n.º 6
0
             $ip_len = 5;
             $ip_frag_flag = "010";
             $ip_frag_oset = "0000000000000";
             $ipv4_hdr->ver_len = $ip_ver . $ip_len;
             $ipv4_hdr->tos = "00";
             $ipv4_hdr->total_len = $size->ip + $size->udp + $size->data;;
             $ipv4_hdr->ident = 19245;
             $ipv4_hdr->fl_fr = 4000;
             $ipv4_hdr->ttl = 30;
             $ipv4_hdr->proto = 17;
             $ipv4_hdr->checksum = 0;
             $ipv4_hdr->src_ip = ip2long($row->source_ip);
             $ipv4_hdr->dst_ip = ip2long($row->destination_ip);
             $pseudo = pack('H2H2nnH4C2nNN', $ipv4_hdr->ver_len,$ipv4_hdr->tos,$ipv4_hdr->total_len, $ipv4_hdr->ident,
                     $ipv4_hdr->fl_fr, $ipv4_hdr->ttl,$ipv4_hdr->proto,$ipv4_hdr->checksum, $ipv4_hdr->src_ip, $ipv4_hdr->dst_ip);
             $ipv4_hdr->checksum = checksum($pseudo);

             $pkt = pack('H2H2nnH4C2nNNnnnna*', $ipv4_hdr->ver_len,$ipv4_hdr->tos,$ipv4_hdr->total_len, $ipv4_hdr->ident,
        	    $ipv4_hdr->fl_fr, $ipv4_hdr->ttl,$ipv4_hdr->proto,$ipv4_hdr->checksum, $ipv4_hdr->src_ip, $ipv4_hdr->dst_ip,
	            $udp_hdr->src_port,$udp_hdr->dst_port, $udp_hdr->length, $udp_hdr->checksum, $data);
        }

	//IP/UDP and DATA header	
	$buf.=$pkt;
}

$pcapfile="HOMER_$fileid";
$pcapfile .= $text ? ".txt" : ".pcap";

// Check if local PCAP or CSHARK enabled
Ejemplo n.º 7
0
     $spamminess += 100;
 }
 $nonascii = preg_split("/[^\n-~]/", $combined);
 $spamminess += count($nonascii) * 300 / strlen($combined);
 foreach ($spamdict as $spamword) {
     $found = stripos($combined, $spamword);
     while ($found !== FALSE) {
         $spamminess += 60;
         $found = stripos($combined, $spamword, $found + 1);
     }
 }
 print "<!-- spamminess={$spamminess} -->\n";
 if ($spamminess >= 100) {
     print "<blink><font color=red>Your spammish-looking message is rejected</font></blink>\n";
 } else {
     if (checksum($_REQUEST['msg']) != $_REQUEST['checksum']) {
         print "<blink><font color=red>Your miscoded message is rejected</font></blink>\n";
     } else {
         if ($_REQUEST['address']) {
             print "<blink><font color=red>Your robot-generated message is rejected</font></blink>\n";
         } else {
             # Guard against duplicate messages
             $result = mysql_query("SELECT msgid FROM calforum WHERE id=\"{$id}\" AND name=\"{$name}\" AND subject=\"{$subject}\" AND msg=\"{$msg}\"", $conn) or die(mysql_error());
             if (mysql_num_rows($result) > 0) {
                 print "<blink><font color=red>Duplicate message rejected</font></blink>\n";
             } else {
                 # Add this message
                 $sql = "INSERT INTO calforum (";
                 $values = " VALUES (";
                 $sql .= "id,";
                 $values .= '"' . $id . '",';
Ejemplo n.º 8
0
    }
    /* the floating point hacks are due to PHP's bugs when handling integers */
    $a = 5381.0;
    for ($i = 0; $i < strlen($str); $i++) {
        $a = fmod($a + $a * 32 + ord($str[$i]), 4294967296.0);
    }
    if ($a > 2147483647.0) {
        $a -= 4294967296.0;
    }
    $a = (int) $a;
    $b = 0.0;
    for ($i = 0; $i < strlen($str); $i++) {
        $b = fmod($b * 64 + $b * 65536 - $b + ord($str[$i]), 4294967296.0);
    }
    if ($b > 2147483647.0) {
        $b -= 4294967296.0;
    }
    $b = (int) $b;
    $a = $a >> 6 & 0x3ffffc0 | $a >> 2 & 0x3f;
    $c = $a >> 4 & 0x3ffc00 | $a & 0x3ff;
    $d = $c >> 4 & 0x3c000 | $c & 0x3fff;
    $c = (($d & 0x3c0) << 4 | $d & 0x3c) << 2;
    $a = $b & 0xf0f;
    $e = $b & 0xf0f0000;
    $b = ($d & 4294950912.0) << 4 | $d & 0x3c00;
    return $b << 10 | $c | $a | $e;
}
$PR_SERVER = "http://toolbarqueries.google.com/tbr?client=navclient-auto&features=Rank&q=info:";
$page = "http://en.wikipedia.org/wiki/Cypherpunk";
$csm = checksum($page);
printf($PR_SERVER . "%s&ch=7%c%u\n", $page, fch($csm), $csm);
Ejemplo n.º 9
0
 public function mkticket($data)
 {
     $this->reload_conf($data['type']);
     $this->img = $this->getimg($GLOBALS['genRoot'] . 'frames/' . $this->conf['img']);
     if (isset($this->conf['gamma'])) {
         imagegammacorrect($this->img, 1.0, $this->conf['gamma']);
     }
     if (isset($data['firstname']) && $data['firstname']) {
         $this->addtext($this->conf['firstname'], $data['firstname']);
     } else {
         $this->addblank($this->conf['firstname']);
     }
     if (isset($data['lastname']) && $data['lastname']) {
         $this->addtext($this->conf['lastname'], $data['lastname']);
     } else {
         $this->addblank($this->conf['lastname']);
     }
     if (isset($data['ticketid'])) {
         $this->addtext($this->conf['ticketid'], $data['ticketid']);
     }
     $this->addtext($this->conf['cb_label'], $data['barcode']);
     checksum($data['barcode']);
     writecode($this->img, $this->conf['codebar'], $data['barcode']);
 }
Ejemplo n.º 10
0
    return substr($sum, -1, 1) === $check;
}
function require_in($cn, $vars)
{
    foreach ($vars as $nm) {
        if (!isset($cn[$nm])) {
            return false;
        }
    }
    return true;
}
if (require_in($_POST, array("name", "nonce", "score", "duration", "cs")) && require_in($_SESSION, array("nonce", "nonce_expires")) && checksum_is_valid($_POST["cs"]) && $_SESSION["nonce_expires"] > time() && $_SESSION["nonce"] === $_POST["nonce"] && intval($_POST["score"]) > 0) {
    unset($_SESSION["nonce"]);
    unset($_SESSION["nonce_expires"]);
    $qs = sprintf("duration=%d&name=%s&nonce=%s&score=%d&snap=%s", urlencode(intval($_POST["duration"])), urlencode($_POST["name"]), urlencode($_POST["nonce"]), urlencode(intval($_POST["score"])), urlencode($_POST["snap"]));
    $cs = checksum($qs);
    if (checksum_is_valid($cs) && $cs === intval($_POST["cs"])) {
        list($meta, $snapdata) = explode(",", $_POST["snap"], 2);
        if ($img = imagecreatefromstring(base64_decode($snapdata))) {
            $snap_fs = sprintf("%s/%s.jpg", SNAPS_FS, $_POST["nonce"]);
            $snap_web = sprintf("%s/%s", SNAPS_WEB, basename($snap_fs));
            if (!imagejpeg($img, $snap_fs)) {
                $snap_web = null;
            }
        }
        $scores[] = implode("|", array(intval($_POST["score"]), floatval($_POST["duration"]), time() * 1000, $snap_web, str_replace("/[^[:alnum:]-_ ]/", "", $_POST["name"])));
        natsort($scores);
        $scores = array_reverse($scores);
        file_put_contents(OUTFILE, implode(PHP_EOL, $scores));
    }
}
Ejemplo n.º 11
0
 $packet .= chr(0);
 // Code
 $packet .= chr(0);
 // Header Checksum
 $packet .= chr(0);
 $packet .= chr($id & 0xff);
 // Identifier
 $packet .= chr($id >> 8);
 $packet .= chr($seq & 0xff);
 // Sequence Number
 $packet .= chr($seq >> 8);
 for ($i = 0; $i < 56; ++$i) {
     // Add 56 bytes of data
     $packet .= chr(0);
 }
 $checksum = checksum($packet);
 $packet[2] = $checksum[0];
 $packet[3] = $checksum[1];
 $start = microtime(true) * MICROSECOND;
 $timeout = $start + MICROSECOND;
 socket_sendto($sock, $packet, strlen($packet), 0, $ip, 0);
 // ICMP doesn't have a port so just use 0
 ++$send;
 for (;;) {
     $now = microtime(true) * MICROSECOND;
     if ($now >= $timeout) {
         echo " *\n";
         break;
     }
     $read = array($sock);
     $other = array();
Ejemplo n.º 12
0
                $discovery = sprintf('{"data":%s}', json_encode($discovery));
                if (json_last_error() != JSON_ERROR_NONE) {
                    exit_error("The error occured while JSON encoding: " . json_last_error() . "\n");
                }
                echo $discovery . "\n";
                break;
            case "sum":
                print_debug("Sum of keys mode\n");
                $sum = 0;
                foreach (array_values($json) as $j) {
                    if (isset($opts["macro"])) {
                        foreach (array_values($opts["macro"]) as $m) {
                            $sum = checksum($sum, array_value($j, $m));
                        }
                    } else {
                        $sum = checksum($sum, $j);
                    }
                }
                echo $sum . "\n";
                break;
            default:
                exit_error("Unknown feature: " . $opts["feature"] . "\n");
        }
    } else {
        if (is_array($json)) {
            exit_error("Result value is array\n");
        }
        echo $json . "\n";
    }
}
exit(0);