} printf("\n"); printf("diff:\n"); for ($i = 0; $i < count($a); $i++) { if ($a[$i] ^ $b[$i]) { printf("%02x,", $a[$i] ^ $b[$i]); } else { printf(" ,"); } } printf("\n\n"); } $key = FieldElement::fromHex($testVectors[0]); $input = FieldElement::fromHex($testVectors[1]); $nonce = FieldElement::fromHex($testVectors[2]); $ad = FieldElement::fromHex($testVectors[3]); $expected = FieldElement::fromHex($testVectors[4]); $ciphertext = Salt::encrypt($input, $ad, $nonce, $key); if (!Salt::equal($expected, $ciphertext)) { echo "encryption error:\n"; printDiff($expected, $ciphertext); } else { echo "encryption OK\n"; } $plaintext = Salt::decrypt($ciphertext, $ad, $nonce, $key); if (!Salt::equal($input, $plaintext)) { echo "decryption error:\n"; printDiff($input, $plaintext); } else { echo "decryption OK\n"; }