Exemplo n.º 1
0
 public function getParidad($mensaje)
 {
     $numero_max = strlen($g) - 1;
     $num = strlen($mensaje);
     $array_mensaje = array();
     for ($a = 0; $a < $num; $a++) {
         $array_mensaje[] = 0 . decbin(ord($mensaje[$a]));
         $mensaje_bin .= decbin(ord($mensaje[$a]));
         $suma_ascii += ord($mensaje[$a]);
         $array_final['suma_bin'] .= 0;
         //echo $mensaje[$a]." - ".decbin(ord($mensaje[$a]))." <br>";
     }
     $suma_bin = decbin($suma_ascii);
     $conteo_hor = 0;
     for ($j = 0; $j < $num; $j++) {
         $valor_par = 0;
         for ($i = 0; $i < 7; $i++) {
             $array_final[$j][$i] = $array_mensaje[$j][$i];
             $valor_par = $array_mensaje[$j][$i] == 1 ? $valor_par + 1 : $valor_par + 0;
         }
         $array_final[$j]['paridad'] = $this->validaParidad($valor_par, $mensaje);
         $conteo_hor += $array_final[$j]['paridad'];
     }
     $array_final['conteo_hor'] = $conteo_hor;
     $array_final['mensaje_bin'] = $mensaje_bin;
     $array_final['suma_bin'] .= $suma_bin;
     return $array_final;
 }
Exemplo n.º 2
0
function GetTypesByDecimal($decimal = 0)
{
    /**
    			 Bit 	=	Type Name					= 	Value store in DB
    			 ------------------------------------------------------------
    			 1		=	Manual Action				=	0
    			 2		=	Offer(automatic)			=	1
    			 4		=	Coupon (automatic)			=	2
    			 8		=	New Affiliates (automatic)	=	3
    			 16		=	New Invoices (automatic)	=	4
    			 32		= 	Products Feed (automatic)	=	5
    			 **/
    $bit_vs_types = array(1 => 0, 2 => 1, 4 => 2, 8 => 3, 16 => 4, 32 => 5);
    if (!$decimal || $decimal < 0) {
        return $decimal;
    }
    echo $decimal . ' = ' . ($decToBin = decbin($decimal));
    echo "<br>";
    $length = $count = strlen($decToBin);
    for ($i = 0; $i < $length; $i++) {
        echo $number = $decToBin[$i] * pow(2, --$count);
        echo "<br>";
        if ($number) {
            $ids[$i] = $bit_vs_types[$number];
        }
    }
    sort($ids);
    return $ids;
}
Exemplo n.º 3
0
function main($num)
{
    if ($num < 0) {
        $s = 1;
        $num = -$num;
    } else {
        $s = 0;
    }
    $zs = floor($num);
    $bzs = decbin($zs);
    $xs = $num - $zs;
    $res = (double) ($bzs . '.' . tenToBinary($xs, 1));
    $teme = ws($res);
    $e = decbin($teme + 127);
    if ($teme == 0) {
        $e = '0' . $e;
    }
    $temm = $res / pow(10, $teme);
    $m = end(explode(".", $temm));
    $lenm = strlen($m);
    if ($lenm < 23) {
        $m .= addzero(23 - $lenm);
    }
    return $s . ' ' . $e . ' ' . $m . ' ';
}
Exemplo n.º 4
0
 /**
  * 获取整形ip
  */
 static function getInt($ip)
 {
     if (self::checkIP($ip)) {
         return bindec(decbin(ip2long($ip)));
     }
     return 0;
 }
Exemplo n.º 5
0
 function index()
 {
     $dota = Dota::me();
     if (isset($this->args[0])) {
         $match_id = (int) $this->args[0];
     }
     if (!empty($match_id)) {
         $steam_ids_array = array();
         $match = $dota->get_match_by_id($match_id);
         foreach ($match['players'] as $key => $player) {
             if ($player['account_id'] == 4294967295.0) {
                 continue;
             }
             $steam_ids_array[$key] = $player['account_id'];
         }
         $profiles = $dota->get_user_profiles($steam_ids_array);
         foreach ($profiles as $key => $profile) {
             $match['players'][$key]['profile'] = $profile;
         }
         $match['tower_radiant'] = decbin(32768 + $match['tower_status_radiant']);
         $match['tower_dire'] = decbin(32768 + $match['tower_status_dire']);
         $match['barak_radiant'] = decbin(128 + $match['barracks_status_radiant']);
         $match['barak_dire'] = decbin(128 + $match['barracks_status_dire']);
         $this->des->set('spells', $dota->get_spells());
         //$this->des->set('arr', $arr['result']);
         $this->des->set('match', $match);
     }
     $this->des->set('dota', $dota);
     $this->des->display('match');
 }
Exemplo n.º 6
0
 function ipMask($ip, $mask)
 {
     $arrip = explode('.', $ip);
     $arrmask = explode('.', $mask);
     $maskip = bindec(decbin($arrip[0]) & decbin($arrmask[0])) . '.' . bindec(decbin($arrip[1]) & decbin($arrmask[1])) . '.' . bindec(decbin($arrip[2]) & decbin($arrmask[2])) . '.' . bindec(decbin($arrip[3]) & decbin($arrmask[3]));
     return $maskip;
 }
Exemplo n.º 7
0
 public function testTransforms()
 {
     $t = new IntMethods();
     $this->assertEquals(decbin(255), $t->getBinary(255));
     $this->assertEquals(dechex(255), $t->getHex(255));
     $this->assertEquals(decoct(255), $t->getOctal(255));
 }
Exemplo n.º 8
0
 /**
  * poller ipAddress
  *
  * @return Array
  */
 public function poll_ipAddress()
 {
     // return
     $_ret = [];
     $snmp = new \App\Lnms\Snmp($this->node->ip_address, $this->node->snmp_comm_ro);
     // walk OID_ipAdEntIfIndex
     $walk_ipAdEntIfIndex = $snmp->walk(OID_ipAdEntIfIndex);
     if (count($walk_ipAdEntIfIndex) == 0 || $walk_ipAdEntIfIndex === false) {
         // not found ipAddress
         return $_ret;
     }
     // walk netmask
     $walk_ipAdEntNetMask = $snmp->walk(OID_ipAdEntNetMask);
     // oid.ipAddress(4) = ifIndex
     foreach ($walk_ipAdEntIfIndex as $key1 => $ifIndex) {
         $ipAddress = str_replace(OID_ipAdEntIfIndex . '.', '', $key1);
         $netmask = explode('.', $walk_ipAdEntNetMask[OID_ipAdEntNetMask . '.' . $ipAddress]);
         if (count($netmask) == 4) {
             $masks = substr_count(decbin($netmask[0]), 1) + substr_count(decbin($netmask[1]), 1) + substr_count(decbin($netmask[2]), 1) + substr_count(decbin($netmask[3]), 1);
         } else {
             $masks = 0;
         }
         $port = \App\Port::where('node_id', $this->node->id)->where('ifIndex', $ifIndex)->first();
         if ($port) {
             // found port and vlan
             $_ret[] = ['table' => 'ips', 'action' => 'sync', 'key' => ['node_id' => $this->node->id, 'port_id' => $port->id], 'data' => ['ipAddress' => $ipAddress, 'masks' => $masks]];
         }
     }
     return $_ret;
 }
Exemplo n.º 9
0
/**
 * 这个程序是针对加密的字符串进行解密
 * @param $str 需要解密的字符串
 * @param $restr 解密完成的代码
 */
function decryption_str($str)
{
    $len = strlen($str);
    $len_b = decbin($len);
    $arr = str_split($str);
    for ($i = 0; $i < $len; $i++) {
        $dec[$i] = ord($arr[$i]);
        $hex[$i] = str_pad(dechex($dec[$i]), 2, 0, STR_PAD_LEFT);
    }
    $str_hex = implode($hex);
    //***2***
    $str_hex = str_ireplace('FF', '00000', $str_hex);
    $str_hex = str_ireplace('EE', '0000', $str_hex);
    $len_s = strlen($str_hex);
    if ($len_s % 2 !== 0) {
        $str_hex = substr($str_hex, 1);
    }
    //***1***
    $arr_hex = str_split($str_hex, 8);
    for ($j = 0; $j < count($arr_hex); $j++) {
        $arr_hex2[$j] = str_split($arr_hex[$j], 2);
        for ($k = 0; $k < 4; $k++) {
            $arr_dec[$j][$k] = sqrt(hexdec($arr_hex2[$j][$k]));
        }
        $dec[$j] = implode($arr_dec[$j]);
        $arr_str[$j] = chr($dec[$j]);
    }
    $restr = implode($arr_str);
    return $restr;
}
Exemplo n.º 10
0
Arquivo: Q.php Projeto: tokushima/ebi
 public function __construct($type = self::AND_BLOCK, $arg1 = null, $arg2 = null, $param = null)
 {
     if ($type === self::AND_BLOCK) {
         $this->and_block = $arg1;
     } else {
         if ($type === self::OR_BLOCK) {
             if (!is_array($arg1) || sizeof($arg1) < 2) {
                 throw new \ebi\exception\InvalidArgumentException('require multiple blocks');
             }
             foreach ($arg1 as $a) {
                 if (!$a->is_block()) {
                     throw new \ebi\exception\InvalidArgumentException('require multiple blocks');
                 }
             }
             $this->or_block = $arg1;
         } else {
             $this->arg1 = $arg1;
         }
     }
     $this->arg2 = $arg2;
     $this->type = $type;
     if ($param !== null) {
         if (!ctype_digit((string) $param)) {
             throw new \ebi\exception\InvalidArgumentException('`' . (string) $param . '` invalid param type');
         }
         $this->param = decbin($param);
     }
 }
Exemplo n.º 11
0
/**
 * Get the number of netmask bits from a netmask in presentation format 
 * 
 * @param string $netmask Netmask in presentation format 
 *  
 * @return integer Number of mask bits 
 * @throws Exception 
 */
function netmask2bitmask($netmask)
{
    try {
        // Validate if $netmask is string
        if (gettype($netmask) !== "string") {
            throw new Exception("Netmask is not a string");
        }
        // Validate if $netmask is IPV4 or IPV6 address
        if (filter_var($netmask, FILTER_VALIDATE_IP) === false) {
            throw new Exception("Netmask is not a IPV4 or IPV6 valid address");
        }
        // Split string into octets or hextets
        $array = preg_split("/\\.|\\:/", $netmask);
        // Convert to binary, delete zeros and get length of resultant string
        if (filter_var($netmask, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) === $netmask) {
            $func = function ($number) {
                return strlen(str_replace("0", "", decbin($number)));
            };
        } else {
            $func = function ($hexa) {
                return strlen(str_replace("0", "", decbin(base_convert($hexa, 16, 10))));
            };
        }
        return array_sum(array_map($func, $array));
    } catch (Exception $ex) {
        print $ex->getMessage();
    }
}
Exemplo n.º 12
0
 /**
  * Prints base-2 (binary) representation of input string
  * @param string $m
  * @param int $rowLength
  * @param string $fillChar
  * @return string
  */
 public static function render($m, $rowLength = 8, $fillChar = ' ')
 {
     $j = 0;
     $bytes = '';
     $row = '';
     $res = '';
     $rowOffset = 0;
     for ($i = 0; $i < strlen($m); $i++) {
         $x = substr($m, $i, 1);
         if (ord($x) > 0x1f && ord($x) < 0x80) {
             $bytes .= $x;
         } else {
             $bytes .= '.';
         }
         $bin = sprintf("%08d", decbin(ord($x)));
         $row .= $bin . $fillChar;
         if (++$j == $rowLength) {
             $res .= sprintf("%06x", $rowOffset) . ": " . $row . ' ' . $bytes . PHP_EOL;
             $rowOffset += $rowLength;
             $bytes = '';
             $row = '';
             $j = 0;
         }
     }
     if ($j) {
         $res .= sprintf("%06x", $rowOffset) . ": " . $row . ' ' . str_repeat(' ', ($rowLength - strlen($bytes)) * 3) . $bytes . PHP_EOL;
     }
     return $res;
 }
 function returnAllergens($input)
 {
     $allergens = array("eggs", "peanuts", "shellfish", "strawberries", "tomaters", "chocolate", "pollen", "cats");
     //define allergens
     $string = decbin($input);
     //converts to binary string<<<<<<<
     $string = strrev($string);
     //flips the string
     while (strlen($string) < count($allergens)) {
         $string .= "0";
     }
     $result = array();
     //define blank result array
     $array = str_split($string);
     // converts binary string into array. $string = "10010000" --> $string = array("1", "0", "0"...)
     foreach ($allergens as $index => $allergy) {
         //for each allergy in $allergens, while tracking its index...
         if ($array[$index] == '1') {
             //if your string array at the positiong of index...--> $string = array("1", "0", "0"...); == 1
             $result[$allergy] = true;
             //assigns into the $result array --> $result = array("eggs"=>true);
         } else {
             $result[$allergy] = false;
             //assigns into the $result array --> $result = array("eggs"=>false);
         }
     }
     return $result;
 }
Exemplo n.º 14
0
 /**
  * 返回客户端的IP地址
  * @param boolean $is_int 所否返回整形IP地址
  * @return int/string $ip 用户IP地址 
  */
 public static function getIp($is_int = false)
 {
     //$ip = false;
     if (!empty($_SERVER['REMOTE_ADDR'])) {
         $ip = $_SERVER["REMOTE_ADDR"];
     } else {
         if (!empty($_SERVER["HTTP_CLIENT_IP"])) {
             $ip = $_SERVER["HTTP_CLIENT_IP"];
         }
     }
     if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
         $ips = explode(", ", $_SERVER['HTTP_X_FORWARDED_FOR']);
         if ($ip) {
             array_unshift($ips, $ip);
             $ip = FALSE;
         }
         for ($i = 0; $i < count($ips); $i++) {
             if (!preg_match("/^(0|10|127|172\\.16|192\\.168)\\./", $ips[$i])) {
                 $ip = $ips[$i];
                 break;
             }
         }
     }
     $ip = $ip ? $ip : $_SERVER['REMOTE_ADDR'];
     $ip = $ip ? $ip : '0.0.0.0';
     return $is_int ? bindec(decbin(ip2long($ip))) : $ip;
 }
Exemplo n.º 15
0
function solution($N)
{
    $new = decbin($N);
    $newarray = str_split($new);
    $i = [];
    $j = 0;
    foreach ($newarray as $key => $value) {
        if ($value == 0) {
            for ($x = 0; x < count($newarray); $x++) {
                if ($newarray[$x] == 0) {
                    $j = $j++;
                } else {
                    break;
                }
            }
            if ($j = count($newarray) - $key - 1) {
                $j = 0;
                $i[] = $j;
            } else {
                $i[] = $j;
            }
        }
        return max($i);
    }
}
Exemplo n.º 16
0
 public function GetLevel($level)
 {
     $levelString = decbin($level);
     //十进制转化二进制
     $levelArray = str_split($levelString);
     $len = count($levelArray);
     if ($len < $this->mLevelNums) {
         $head = array();
         for ($i = 0; $i < $this->mLevelNums - $len; $i++) {
             $head[$i] = 0;
         }
     } else {
         $head = array();
     }
     $levelArray = array_merge($head, $levelArray);
     $j = 0;
     //echo $this->mLevelNums;
     for ($i = $this->mLevelNums - 1; $i >= 0; $i--) {
         if ($levelArray[$i] == 1) {
             //拥有$i号权限
             $returnArray[$j] = $this->mLevelNums - $i - 1;
             $j++;
         } else {
             //不存在$i号权限
             continue;
         }
     }
     if ($j == 1) {
         return $returnArray[0];
     }
     return $j > 0 ? $returnArray : -1;
 }
Exemplo n.º 17
0
 /**
  *@desc 截取字符串
  *@param $string 需要截取的字符串
  *@param $length 需要截取的字符长度$length 汉字为2倍
  *@param $etc 后缀
  *@return string
  **/
 public static function cutStr($string, $length, $etc = '...')
 {
     $result = '';
     $string = html_entity_decode(trim(strip_tags($string)), ENT_QUOTES, 'UTF-8');
     //$string   =   trim($string);
     $strlen = strlen($string);
     for ($i = 0; $i < $strlen && $length > 0; $i++) {
         if ($number = strpos(str_pad(decbin(ord(substr($string, $i, 1))), 8, '0', STR_PAD_LEFT), '0')) {
             if ($length < 1.0) {
                 break;
             }
             $result .= substr($string, $i, $number);
             $length -= 1.0;
             $i += $number - 1;
         } else {
             $result .= substr($string, $i, 1);
             $length -= 0.5;
         }
     }
     $result = htmlspecialchars($result, ENT_QUOTES, 'UTF-8');
     if ($i < $strlen) {
         $result .= $etc;
     }
     return $result;
 }
Exemplo n.º 18
0
 /**
  * poller routeDest
  *
  * @return Array
  */
 public function poll_routeDest()
 {
     // return
     $_ret = [];
     $snmp = new \App\Lnms\Snmp($this->node->ip_address, $this->node->snmp_comm_ro);
     // walk ipRouteIfIndex
     $walk_ipRouteIfIndex = $snmp->walk(OID_ipRouteIfIndex);
     if (count($walk_ipRouteIfIndex) == 0) {
         // not found route
         return $_ret;
     }
     //
     $walk_ipRouteNextHop = $snmp->walk(OID_ipRouteNextHop);
     $walk_ipRouteType = $snmp->walk(OID_ipRouteType);
     $walk_ipRouteProto = $snmp->walk(OID_ipRouteProto);
     $walk_ipRouteMask = $snmp->walk(OID_ipRouteMask);
     // oid.routeDest = ifIndex
     foreach ($walk_ipRouteIfIndex as $key1 => $ifIndex) {
         $routeDest = str_replace(OID_ipRouteIfIndex . '.', '', $key1);
         $routeNextHop = $walk_ipRouteNextHop[OID_ipRouteNextHop . '.' . $routeDest];
         $routeType = $walk_ipRouteType[OID_ipRouteType . '.' . $routeDest];
         $routeProto = $walk_ipRouteProto[OID_ipRouteProto . '.' . $routeDest];
         $netmask = explode('.', $walk_ipRouteMask[OID_ipRouteMask . '.' . $routeDest]);
         $routeMasks = substr_count(decbin($netmask[0]), 1) + substr_count(decbin($netmask[1]), 1) + substr_count(decbin($netmask[2]), 1) + substr_count(decbin($netmask[3]), 1);
         $port = \App\Port::where('node_id', $this->node->id)->where('ifIndex', $ifIndex)->first();
         if ($port) {
             // found port
             $_ret[] = ['table' => 'routes', 'action' => 'sync', 'key' => ['node_id' => $this->node->id, 'port_id' => $port->id, 'routeDest' => $routeDest, 'routeMasks' => $routeMasks], 'data' => ['routeNextHop' => $routeNextHop, 'routeType' => $routeType, 'routeProto' => $routeProto]];
         }
     }
     return $_ret;
 }
Exemplo n.º 19
0
 public static function getBanco()
 {
     if (!isset($_SESSION['senhaBanco'])) {
         $arquivo = fopen("pass.txt", "r");
         $aux = fscanf($arquivo, "%s\t%s");
         $_SESSION['chave'] = $aux[1];
         $texto = Atalhos::decode($aux[0]);
         $tm = strlen($texto);
         //conta a quantidade de caracteres do texto
         $x = 0;
         $buf = "";
         for ($i = 1; $i <= $tm; $i++) {
             $letra[$i] = substr($texto, $x, 1);
             //isola cada caractere da string
             $cod[$i] = ord($letra[$i]);
             //converte cada caractere em seu respectivo codigo ascii
             $bin[$i] = decbin($cod[$i]);
             //converte cada codigo ascii em seu respectivo codigo binario
             if ($bin[$i] == 0) {
                 break;
             }
             $buf = $buf . $letra[$i];
             $x++;
         }
         $_SESSION['senhaBanco'] = $buf;
     }
     $db = new mysqli('localhost', 'root', $_SESSION['senhaBanco'], 'lcad');
     $db->set_charset("utf8");
     return $db;
 }
Exemplo n.º 20
0
 public static function timeFromParticle($particle)
 {
     /*
      * Return time
      */
     return bindec(substr(decbin($particle), 0, 41)) - pow(2, 40) + 1 + self::EPOCH;
 }
Exemplo n.º 21
0
 public function strdecodebase32($str)
 {
     if (strlen($str) % 8 > 0) {
         throw new Exception("Str length must be a multiple of 8");
     }
     if (empty($str)) {
         return "";
     }
     $len = strpos($str, "=");
     if ($len !== FALSE) {
         $str = substr($str, 0, $len);
     }
     $quanta = str_split($str, 8);
     $decoded = "";
     foreach ($quanta as $quantum) {
         $_8bitchars = "";
         for ($i = 0; $i < strlen($quantum); $i++) {
             $code = strpos($this->charset, $quantum[$i]);
             if ($code === FALSE) {
                 throw new Exception("Invalid charset.");
             }
             $_8bitchars .= str_pad(decbin($code), 5, "0", STR_PAD_LEFT);
         }
         foreach (str_split($_8bitchars, 8) as $char) {
             $decoded .= chr(bindec($char));
         }
     }
     return $decoded;
 }
Exemplo n.º 22
0
function bacon_encode(WC_Challenge $chall, $hidden)
{
    $message = strtolower($chall->lang('message'));
    $len = strlen($hidden);
    $pos = -1;
    $a = ord('A');
    for ($i = 0; $i < $len; $i++) {
        $c = ord($hidden[$i]);
        $bin = decbin($c - $a);
        $bin = sprintf('%05d', $bin);
        for ($j = 0; $j < 5; $j++) {
            $pos = bacon_next_pos($message, $pos);
            if ($bin[$j] === '1') {
                $message[$pos] = strtoupper($message[$pos]);
            }
        }
    }
    $pos++;
    $len = strlen($message);
    while ($pos < $len) {
        $message[$pos] = strtoupper($message[$pos]);
        $pos += 2;
    }
    return $message;
}
Exemplo n.º 23
0
 /**
  * Encode value into varint string
  *
  * @param integer $value
  * @return string
  */
 public static function encode($value)
 {
     if (!is_integer($value) || $value < 0) {
         throw new PhpBuf_Base128_Exception("value mast be unsigned integer");
     }
     if ($value <= 127) {
         return chr($value);
     }
     $result = '';
     $bin = decbin($value);
     $bit8 = '1';
     $index = strlen($bin);
     $substrLenght = 7;
     while (0 < $index) {
         if ($index < 8) {
             $bit8 = '0';
         }
         $index = $index - 7;
         if ($index < 0) {
             $substrLenght = $substrLenght + $index;
             $index = 0;
         }
         $bin7bit = substr($bin, $index, $substrLenght);
         $dec = bindec($bit8 . $bin7bit);
         $char = chr($dec);
         $result = $result . $char;
     }
     return $result;
 }
Exemplo n.º 24
0
 public function decode($data)
 {
     if (!is_string($data)) {
         throw new Exception('The data must be a string.');
     }
     if (empty($data)) {
         return '';
     }
     if ($this->dictionnary === null) {
         throw new Exception('The dictionnary has not been set.');
     }
     $binaryString = '';
     $dataLenght = strlen($data);
     $uncompressedData = '';
     for ($i = 0; $i < $dataLenght; ++$i) {
         $decbin = decbin(ord($data[$i]));
         while (strlen($decbin) < 8) {
             $decbin = '0' . $decbin;
         }
         if (!$i) {
             $decbin = substr($decbin, strpos($decbin, '1') + 1);
         }
         if ($i + 1 == $dataLenght) {
             $decbin = substr($decbin, 0, strrpos($decbin, '1'));
         }
         $binaryString .= $decbin;
         while (($c = $this->dictionnary->getEntry($binaryString)) !== null) {
             $uncompressedData .= $c;
         }
     }
     return $uncompressedData;
 }
Exemplo n.º 25
0
 /**
  * Dekóduje vložený řetězec
  * @param mixed $data  data pro dekodování
  * @param mixed $slovnik slovník pro dekódvání
  * @return dekódovaný string
  */
 public function dekoduj($data)
 {
     $hledanyString = '';
     $vysledek = '';
     for ($i = 0; $i < strlen($data); ++$i) {
         $nactenyString = decbin(ord($data[$i]));
         // prevedení z charu na binární číslo
         while (strlen($nactenyString) < 8) {
             //dpolnění 0 pokud chybí místa
             $nactenyString = '0' . $nactenyString;
         }
         if (!$i) {
             //první průchod - ořízne první 1
             $nactenyString = substr($nactenyString, strpos($nactenyString, '1') + 1);
         }
         if ($i + 1 == strlen($data)) {
             //poslední průchod - ořízne poslední 1
             $nactenyString = substr($nactenyString, 0, strrpos($nactenyString, '1'));
         }
         $hledanyString .= $nactenyString;
         while (($c = $this->slovnik->ziskejZnak($hledanyString)) !== null) {
             $vysledek .= $c;
         }
     }
     return $vysledek;
 }
Exemplo n.º 26
0
function calcSmallest($packets, $weight)
{
    $checkStr = implode(array_fill(0, count($packets), 1));
    $checkDec = bindec($checkStr);
    for ($i = 0; $i <= $checkDec; $i++) {
        $binStr = decbin($i);
        if (isset($smallest) && substr_count($binStr, "1") > $smallest[0]) {
            continue;
        }
        $binStrArr = str_split(str_pad($binStr, count($packets), "0", STR_PAD_LEFT));
        $new_vals = [];
        foreach ($binStrArr as $key => $value) {
            $new_vals[] = $value * $packets[$key];
        }
        $new_vals = array_filter($new_vals);
        if (array_sum($new_vals) == $weight) {
            $newLen = count($new_vals);
            $newQuan = array_product($new_vals);
            if (isset($smallest)) {
                if ($newLen <= $smallest[0] && $newQuan < $smallest[1]) {
                    $smallest = [$newLen, $newQuan];
                }
            } else {
                $smallest = [$newLen, $newQuan];
            }
        }
    }
    return $smallest[1];
}
Exemplo n.º 27
0
 public function Geohash()
 {
     //build map from encoding char to 0 padded bitfield
     for ($i = 0; $i < 32; $i++) {
         $this->codingMap[substr($this->coding, $i, 1)] = str_pad(decbin($i), 5, "0", STR_PAD_LEFT);
     }
 }
Exemplo n.º 28
0
function cidr_conv($net)
{
    $start = strtok($net, '/');
    $n = 3 - substr_count($net, '.');
    if ($n > 0) {
        for ($i = $n; $i > 0; $i--) {
            $start .= '.0';
        }
    }
    $bits1 = str_pad(decbin(ip2long($start)), 32, '0', 'STR_PAD_LEFT');
    $net = pow(2, 32 - substr(strstr($net, '/'), 1)) - 1;
    $bits2 = str_pad(decbin($net), 32, '0', 'STR_PAD_LEFT');
    $final = '';
    for ($i = 0; $i < 32; $i++) {
        if ($bits1[$i] == $bits2[$i]) {
            $final .= $bits1[$i];
        }
        if ($bits1[$i] == 1 && $bits2[$i] == 0) {
            $final .= $bits1[$i];
        }
        if ($bits1[$i] == 0 && $bits2[$i] == 1) {
            $final .= $bits2[$i];
        }
    }
    return $start . " - " . long2ip(bindec($final));
}
Exemplo n.º 29
0
 /**
  * Customises the backup progress bar
  *
  * @global moodle_page $PAGE
  * @return array
  */
 public function get_progress_bar()
 {
     global $PAGE;
     $stage = self::STAGE_COMPLETE;
     $currentstage = $this->stage->get_stage();
     $items = array();
     while ($stage > 0) {
         $classes = array('backup_stage');
         if (floor($stage / 2) == $currentstage) {
             $classes[] = 'backup_stage_next';
         } else {
             if ($stage == $currentstage) {
                 $classes[] = 'backup_stage_current';
             } else {
                 if ($stage < $currentstage) {
                     $classes[] = 'backup_stage_complete';
                 }
             }
         }
         $item = array('text' => strlen(decbin($stage * 2)) . '. ' . get_string('importcurrentstage' . $stage, 'backup'), 'class' => join(' ', $classes));
         if ($stage < $currentstage && $currentstage < self::STAGE_COMPLETE && (!self::$skipcurrentstage || $stage * 2 != $currentstage)) {
             $item['link'] = new moodle_url($PAGE->url, $this->stage->get_params() + array('backup' => $this->get_backupid(), 'stage' => $stage));
         }
         array_unshift($items, $item);
         $stage = floor($stage / 2);
     }
     $selectorlink = new moodle_url($PAGE->url, $this->stage->get_params());
     $selectorlink->remove_params('importid');
     array_unshift($items, array('text' => '1. ' . get_string('importcurrentstage0', 'backup'), 'class' => join(' ', $classes), 'link' => $selectorlink));
     return $items;
 }
Exemplo n.º 30
0
 /**
  * Return an array of active bits in the binary representation of the given integer
  * @param integer $int
  * @return array
  */
 public static function getBitArrayFromInt($int)
 {
     $binstr = (string) decbin($int);
     $binarr = array_reverse(str_split($binstr));
     $bitarr = array_keys($binarr, '1', true);
     return $bitarr;
 }