Noka/Infinity Test Code For Version 1.00.00

Advertisement

<?php
include_once ('noka-encryption.lib.php');

###########################################################################################
#                                                                                         #
#    Copyright 2018 Khang H. Nguyen (kevinhg86)                                           #
#    E-mail: kevin@fai.host | Web: http://kevinhng86.iblog.website                        #
#    Contributors: https://github.com/kevinhng86/noka-encryption/blob/master/CONTRIBUTORS #                                                    #
#                                                                                         #    
#                                                                                         #
#    Permission is hereby granted, free of charge, to any person obtaining a copy         #
#    of this software and associated documentation files (the "Software"), to deal        #
#    in the Software without restriction, including without limitation the rights         #
#    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies     #
#    of the Software, and to permit persons to whom the Software is furnished             # 
#    to do so, subject to the following conditions:                                       #
#                                                                                         #
#    The above copyright notice and this permission notice shall be  included in all      #
#    copies or substantial portions of the Software.                                      #
#                                                                                         #
#    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR           #
#    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,             #
#    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL              #
#    THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER           #
#    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,        #
#    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN            #
#    THE SOFTWARE.                                                                        #
#                                                                                         #
###########################################################################################

$nk = new noka_encryption;

// VERIFY_NK_HASH() TEST CODE: TEST MATCH //
echo "\n\n\n==========TESTING NK_HASH() & VERIFY_NK_HASH(): TEST MATCH==========\n\n\n";
$round = 10000;
$algos_list = array('sha512', 'sha256', 'gost', 'ripemd320', 'haval256,5');
$allen = count($algos_list) - 1;
$error = false; 
$time_start = microtime(true);

   
for ($i = 0; $i < $round; $i++ ){
    
    $algos = array();
    $algos_amount = mt_rand(3,50);
    $rounds = mt_rand(3, 500);    
    $keys = array();
    $keys_amount = mt_rand(3, 50);
    $str = '';  
    $len = mt_rand(1,1000);
    $hex_detect_key = mt_rand(0,1) === 1;
    
    while ( $algos_amount > 0 ){
        $algos[] = $algos_list[ mt_rand(0, $allen) ];
        $algos_amount--;  
    }
    
    while( $keys_amount > 0 ){
        $keys[] = $nk->generate_key( mt_rand(1, 32) );
        $keys_amount--;
    }
    
    while ( $len > 0 ){
        $str .= chr( mt_rand(1, 255) );
        $len--;
    }
        
    $b = $nk->nk_hash( $str, $rounds, $keys, $algos, $hex_detect_key );
    $c = $nk->verify_nk_hash( $str, $b, $rounds, $keys, $algos, $hex_detect_key);
    if ( $c !== true ){
         echo "Not match \n";
         $error = true;
    }
}

echo "Time Took: ", number_format( microtime(true) - $time_start, 4 ), PHP_EOL;
if ( $error === true ) echo "TEST FAIL\n" ; else echo "TEST PASS\n";

// END OF VERIFY_HASHX TEST CODE: TEST MATCH 


// VERIFY_NK_HASH() TEST CODE: TEST UNMATCH //
echo "\n\n\n==========TESTING NK_HASH() & VERIFY_NK_HASH(): UNMATCH==========\n\n\n";
$round = 10000;
$algos_list = array('sha512', 'sha256', 'gost', 'ripemd320', 'haval256,5');
$allen = count($algos_list) - 1;
$error = false; 
$time_start = microtime(true);

   
for ($i = 0; $i < $round; $i++ ){
    
    $algos = array();
    $algos_amount = mt_rand(3,50);
    $rounds = mt_rand(3, 50);    
    $keys = array();
    $keys_amount = mt_rand(3, 50);
    $str = '';  
    $len = mt_rand(1,1000);
    $hex_detect_key = mt_rand(0,1) === 1;
    
    while ( $algos_amount > 0 ){
        $algos[] = $algos_list[ mt_rand(0, $allen) ];
        $algos_amount--;  
    }
    
    while( $keys_amount > 0 ){
        $keys[] = $nk->generate_key( mt_rand(1, 32) );
        $keys_amount--;
    }
    
    while ( $len > 0 ){
        $str .= chr( mt_rand(1, 255) );
        $len--;
    }
        
    $b = $nk->nk_hash( $str, $rounds, $keys, $algos, $hex_detect_key );
    // ********************** //
    $algos = array();
    $algos_amount = mt_rand(3,50);
    $rounds = mt_rand(3, 500);    
    $keys = array();
    $keys_amount = mt_rand(3, 50);
    $str = '';  
    $len = mt_rand(1,1000);
    $hex_detect_key = mt_rand(0,1) === 1;
    
    while ( $algos_amount > 0 ){
        $algos[] = $algos_list[ mt_rand(0, $allen) ];
        $algos_amount--;  
    }
    
    while( $keys_amount > 0 ){
        $keys[] = $nk->generate_key( mt_rand(1, 32) );
        $keys_amount--;
    }
    
    while ( $len > 0 ){
        $str .= chr( mt_rand(1, 255) );
        $len--;
    }
    
    $c = $nk->verify_nk_hash( $str, $b, $rounds, $keys, $algos, $hex_detect_key);
    if ( $c === true ){
         echo "Not match \n";
         $error = true;
    }
}

echo "Time Took: ", number_format( microtime(true) - $time_start, 4 ), PHP_EOL;
if ( $error === true ) echo "TEST FAIL\n" ; else echo "TEST PASS\n";

// END OF VERIFY_HASHX TEST CODE: TEST UNMATCH


// VERIFY_NK_HASHC TEST CODE //
echo "\n\n\n==========TESTING NK_HASHC() & VERIFY_NK_HASHC()==========\n\n\n";
$round = 20000;
$error = false;
$time_start = microtime(true);

for ($i = 0; $i < $round; $i++ ){
    
    $str = '';  
    $len = mt_rand(1,1000);
    $hex_detect_key = mt_rand(0,1) === 1;
    
    while ( $len > 0 ){
        $str .= chr( mt_rand(1, 255) );
        $len--;
    }
        
    $b = $nk->nk_hashc( $str, $hex_detect_key );
    $c = $nk->verify_nk_hashc( $str, $b, $hex_detect_key);
    if ( $c !== true ){
         echo "Not match \n";
         $error = true;
    }
}

echo "Time Took: ", number_format( microtime(true) - $time_start, 4 ), PHP_EOL;
if ( $error === true ) echo "TEST FAIL\n" ; else echo "TEST PASS\n";
// END OF VERIFY_NK_HASHC TEST CODE */




// VERIFY_HASHX TEST CODE //
echo "\n\n\n==========TESTING HASHX() & VERIFY_HASHX()==========\n\n\n";
$round = 20000;
$algos_list = array('sha512', 'sha256', 'gost', 'ripemd320', 'haval256,5');
$allen = count($algos_list) - 1;
$error = false; 
$time_start = microtime(true);

   
for ($i = 0; $i < $round; $i++ ){
    
    $algos = array();
    $algos_amount = mt_rand(1,100);
    $rounds = mt_rand(1, 1000);    
    $hex_detect_key = mt_rand(0,1) === 1;
    $keys_amount = mt_rand(1, 100);
    $keys = array();
    $len = mt_rand(1,1000);
    $str = '';  
    
    while ( $algos_amount > 0 ){
        $algos[] = $algos_list[ mt_rand(0, $allen) ];
        $algos_amount--;  
    }
    
    while( $keys_amount > 0 ){
        $keys[] = mt_rand(0,1) === 1? $nk->generate_key( mt_rand(1, 32) ) : '';
        $keys_amount--;
    }
    
    while ( $len > 0 ){
        $str .= chr( mt_rand(1, 255) );
        $len--;
    }
        
    $b = $nk->hashx( $str, $rounds, $keys, $algos, $hex_detect_key );
    $c = $nk->verify_hashx( $str, $b, $rounds, $keys, $algos, $hex_detect_key);
    if ( $c !== true ){
         echo "Not match \n";
         $error = true;
    }
}

echo "Time Took: ", number_format( microtime(true) - $time_start, 4 ), PHP_EOL;
if ( $error === true ) echo "TEST FAIL\n" ; else echo "TEST PASS\n";

// END OF VERIFY_HASHX TEST CODE */




// VERIFY_HASHCRYPT TEST CODE //
echo "\n\n\n==========TESTING HASHCRYPT() & VERIFY_HASHCRYPT()==========\n\n\n";
$round = 10000;
$error = false;
$time_start = microtime(true);

for ($i = 0; $i < $round; $i++ ){
    
    
    $hash_algo_list = array('sha512', 'sha256', 'gost', 'ripemd320', 'haval256,5');
    $hash_algo = $hash_algo_list[ mt_rand(0, count($hash_algo_list) - 1  ) ];
    $crypt_algo_list = array('blowfish', 'sha256', 'sha512');
    $crypt_algo = $crypt_algo_list[ mt_rand(0, count($crypt_algo_list) - 1  ) ];
    $hex_detect_key = mt_rand(0,1) === 1? true : false;
 
 
    $mode = mt_rand(0, 2);
    
    $hash_key = $nk->generate_key( mt_rand(1, 32) );
    $len = mt_rand(1,1000);
    $str = '';  
    
    while ( $len > 0 ){
        $str .= chr( mt_rand(1, 255) );
        $len--;
    }    

    $b = $nk->hashcrypt( array(
        'password' => $str,
        'hash_key' => $hash_key,
        'hex_detect_key' => $hex_detect_key,
        'crypt_algo' => $crypt_algo,
        'hash_algo' => $hash_algo,
        'mode' => $mode,
    ));

    $c = $nk->verify_hashcrypt( array(
        'password' => $str,
        'crypt_string' => $b,
        'hash_algo' => $hash_algo,
        'hash_key' => $hash_key,
        'hex_detect_key' => $hex_detect_key,
        'mode' => $mode
    ));
    
    if ( $c !== true ){
         echo "Not match \n";
         $error = true;
    }
}

echo "Time Took: ", number_format( microtime(true) - $time_start, 4 ), PHP_EOL;
if ( $error === true ) echo "TEST FAIL\n" ; else echo "TEST PASS\n";

// END OF VERIFY_HASHCRYPT TEST CODE */


// NK_ENCRYPT TEST CODE //

echo "\n\n\n==========TESTING NK_ENCRYPT() & NK_DECRYPT()==========\n\n\n";
$round = 50000;
$error = false;
$time_start = microtime(true);

for ($i = 0; $i < $round; $i++ ){
    
    
    $algolist = array('aes-256-xts', 'bf-ecb', 'aes-256-ctr', 'camellia-256-cbc', 'aes-128-cbc', 'aes-192-cbc', 'aes-192-ecb', 'des-ede-cbc', 'des-ede-cfb', 'des-ede-ofb');
    $allen = count($algolist) - 1;
    $algoamount = mt_rand(1,10);
    $algos = array();
    $rounds = mt_rand(1, 15);
    $mode = mt_rand(0, 2);
    
    $keyamount = mt_rand(1,20);
    $keys = array();
    $len = mt_rand(1,1000);
    $str = '';
    $hex_detect_key = mt_rand(0,1) === 1? true : false;
    
    while ( $algoamount > 0 ){
        $algos[] = $algolist[ mt_rand(0, $allen ) ];
        $algoamount--;
    }
    
    while ( $keyamount > 0 ){
        $keylen = mt_rand(1, 24);
        $keys[] = $nk->generate_key($keylen);
        $keyamount--;
    }
  
    
    while ( $len > 0 ){
        $str .= chr( mt_rand(1, 255) );
        $len--;
    }    

    $b = $nk->nk_encrypt($str, $rounds, $keys, $algos, $mode, $hex_detect_key);

    $c = $nk->nk_decrypt($b, $rounds, $keys, $algos, $mode, $hex_detect_key ); 
    if ( $c !== $str ){
        echo "Not match \n";
        $error = true;
    }
}

echo "Time Took: ", number_format( microtime(true) - $time_start, 4 ), PHP_EOL;
if ( $error === true ) echo "TEST FAIL\n" ; else echo "TEST PASS\n";

// END NK_ENCRYPT TEST CODE // */
Advertisement


Random Article You May Like