예제 #1
0
function ivcs_transform_from($six_word)
{
    global $rev_ivcs;
    if (!is_array($six_word)) {
        error_log("*************** non - array argument ****************");
        error_log("ivcs_transform_from :  non-array argument");
        return false;
        //  conversion to an array
        //  is responsibility of calling routines
    }
    /* translate all six words into
       unsigned long versions of their
       int values as defined by their offset
       into $ivcs (iso-646 2048-word dictionary) */
    $binArray = array();
    for ($i = 0; $i < 6; $i++) {
        $lutIndex = strtoupper($six_word[$i]);
        $packedIndex = pack("L", $rev_ivcs[$lutIndex]);
        $wordArray = str2arr(ulong2binstr($packedIndex));
        $binArray = array_merge($binArray, array_slice($wordArray, 21, 11));
    }
    $checksumCheckArray = rfc2289_checksum($binArray);
    if ($binArray[64] != $checksumCheckArray[0] || $binArray[65] != $checksumCheckArray[1]) {
        error_log("***************checksum error!****************");
        error_log("ivcs_transform_from :  Checksum error");
        return false;
    }
    return booleanArray_2_hexString(array_slice($binArray, 0, 64));
}
예제 #2
0
function lshft_ulong($ulong, $amount, $wrap = 0)
{
    $orig = str2arr(ulong2binstr($ulong));
    for ($i = 0; $i < $amount; ++$i) {
        /* have to init array because php glues arrays not in order of keys,
           but in order of insertion into the array.  Another undocumented "feature"  */
        for ($k = 0; $k < 32; ++$k) {
            $shifted[$k] = '';
        }
        for ($j = 31; $j >= 0; --$j) {
            if ($j == 31) {
                $shifted[$j] = $wrap;
            } else {
                $shifted[$j] = $orig[$j + 1];
            }
        }
        for ($k = 0; $k < 31; ++$k) {
            $shifted[$k] = $shifted[$k];
        }
        #print "<H1>|".implode('',$orig)."|".implode('',$shifted)."|</H1>";
        $orig = $shifted;
    }
    return strbin2ulong($shifted);
}