Beispiel #1
0
#!/usr/bin/php
<?php 
require_once '../Anubis.php';
$cypher = new vtvz\anubis\Anubis();
$test_vectors = explode("\n\n", file_get_contents('test-vectors.txt'));
$success = true;
$k = 1;
foreach ($test_vectors as $test) {
    list($key, $plain, $cipher, $decrypted, $iterated_100, $iterated_1000) = explode("\n", trim($test));
    $key = hex2bin($key);
    $plain = hex2bin($plain);
    $decrypted = hex2bin($decrypted);
    $cypher->setKey($key, true);
    $my_cipher = $cypher->encrypt($plain);
    $my_decrypted = $cypher->decrypt($my_cipher);
    $success = $success && $my_decrypted === $decrypted;
    echo $k++, "/", sizeof($test_vectors), ":\n";
    echo '      key = ', bin2hex($key), "\n", '    plain = ', bin2hex($plain), "\n", '   cipher = ', bin2hex($my_cipher), "\n", 'decrypted = ', bin2hex($my_decrypted), "\n";
    echo "Result: ", $success ? "OK" : "WRONG", "\n\n";
}
echo "Common result: ", $success ? "OK" : "WRONG", "\n";
Beispiel #2
0
#!/usr/bin/php
<?php 
require_once '../Anubis.php';
$src = 'test-file.txt';
$encrypted = 'encrypted.file';
$decrypted = 'test-file-decrypted.txt';
$time = microtime(true);
$cypher = new vtvz\anubis\Anubis();
//never do it if file supposed to be greater than several KB
//$cypher->file_blocksize = filesize($src);
$cypher->setKey("", true);
$cypher->encryptFile($src, $encrypted);
$cypher->decryptFile($encrypted, $decrypted);
$time = microtime(true) - $time;
$src_hash = md5_file($src);
$decrypted_hash = md5_file($decrypted);
echo "Src:  {$src_hash}\n";
echo "Dest: {$decrypted_hash}\n";
echo "Time: {$time} s\n";