- var_dump: documentation ( source)
- bin2hex: documentation ( source)
- hash: documentation ( source)
- ord: documentation ( source)
<?php
$bit1_flag= 1 << 7;
$bit2_flag= 1 << 6;
// (and i know the fugly for loop should be a do{}while() instead, anyone feel free to fix it, idc)
for($i=0;$i<PHP_INT_MAX;++$i){
$str=(string)$i;
$hash=hash("sha1",$str,true);
$ord=ord($hash[0]);
if(($ord & $bit1_flag) || ($ord & $bit2_flag)){
continue;
}
break;
}
function strtobits(string $str):string{
$ret="";
for($i=0;$i<strlen($str);++$i){
$ord=ord($str[$i]);
for($bitnum=7;$bitnum>=0;--$bitnum){
if($ord & (1<<$bitnum)){
$ret.="1";
}else{
$ret.="0";
}
}
}
return $ret;
}
var_dump($str,strtobits($hash),bin2hex($hash));