tests added and XXTEA not working correctly fixed

This commit is contained in:
Luis Martinez 2022-07-11 19:38:59 -05:00
parent 653af6a300
commit c14098a27c
2 changed files with 65 additions and 3 deletions

View File

@ -73,7 +73,7 @@ class XXTEAEncrypt extends Operation {
* @returns {string}
*/
toBinaryString(v, includeLENGTH) {
const LENGTH = v.LENGTH;
const LENGTH = v.length;
let n = LENGTH << 2;
if (includeLENGTH) {
const M = v[LENGTH - 1];
@ -120,7 +120,7 @@ class XXTEAEncrypt extends Operation {
* @returns {Uint32Array}
*/
encryptUint32Array(v, k) {
const LENGTH = v.LENGTH;
const LENGTH = v.length;
const N = LENGTH - 1;
let y, z, sum, e, p, q;
z = v[N];
@ -159,7 +159,7 @@ class XXTEAEncrypt extends Operation {
* @returns {Uint32Array}
*/
convertToUint32Array(bs, includeLength) {
const LENGTH = bs.LENGTH;
const LENGTH = bs.length;
let n = LENGTH >> 2;
if ((LENGTH & 3) !== 0) {
++n;

View File

@ -0,0 +1,62 @@
/**
* Base64 tests.
*
* @author devcydo [devcydo@gmail.com]
*
* @copyright Crown Copyright 2022
* @license Apache-2.0
*/
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([
{
name: "XXTEA",
input: "Hello World! 你好,中国!",
expectedOutput: "QncB1C0rHQoZ1eRiPM4dsZtRi9pNrp7sqvX76cFXvrrIHXL6",
reecipeConfig: [
{
args: "1234567890"
},
],
},
{
name: "XXTEA",
input: "ნუ პანიკას",
expectedOutput: "PbWjnbFmP8Apu2MKOGNbjeW/72IZLlLMS/g82ozLxwE=",
reecipeConfig: [
{
args: "1234567890"
},
],
},
{
name: "XXTEA",
input: "ნუ პანიკას",
expectedOutput: "dHrOJ4ClIx6gH33NPSafYR2GG7UqsazY6Xfb0iekBY4=",
reecipeConfig: [
{
args: "ll3kj209d2"
},
],
},
{
name: "XXTEA",
input: "",
expectedOutput: "Invalid input length (0)",
reecipeConfig: [
{
args: "1234567890"
},
],
},
{
name: "XXTEA",
input: "",
expectedOutput: "Invalid input length (0)",
reecipeConfig: [
{
args: ""
},
],
},
]);