AnyankaKeys/Public/tests/index.html

390 lines
18 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<title data-i18n="anyanka_title_test_base">Full test - AnyankaKeys</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<style>html,body{background-color : #222;}</style>
<script src="../ecma/AnyankaKeys.ecma.js" charset="utf-8"></script>
<script charset="utf-8">
// https://anyankakeys.local/tests
const options = {
// Nullish || Boolean || Integer
summatory : null,
incremental : true,
random_private_start : null,
// scape_block : 1 << 3
};
const anyanka_keys = new AnyankaKeys(options);
const timeout = 1,
// maximum_character = [0xFE, 0xFFFE];
maximum_character = [0xFF, 0xFFFF];
// maximum_character = [0xFE, 0xFE];
let running = true;
const random_character = (i, maximum) => {
let code = 0;
do{
code = Math.random() * maximum_character[0] >> 0;
}while(
(!i && (!code || (options.scape_block & (1 << 3) && code < 0x100))) ||
(code & 0xFF == 92 || (code >> 8) & 0xFF == 92)
);
return String.fromCharCode(code);
};
const random = {
undefined : (level = 0) => undefined,
null : (level = 0) => null,
string : (level = 0) => new Array(Math.random() * 100 >> 0).fill("").map(
level ? (_, i) => random_character(maximum_character[0], i) :
(_, i) => random_character(maximum_character[1], i)).join(""),
integer : (level = 0) => Math.random() * 2 ** 28 >> 0,
// integer : (level = 0) => 2 ** (Math.random() * 28 >> 0),
array : (level = 0) => level > 2 ? [] : new Array(Math.random() * 100 >> 0).fill(0).map(() => get_random(level)),
boolean : (level = 0) => Math.random() > .5,
bytes : (level = 0) => new Array(Math.random() * 100 >> 0).fill(0).map(() => Math.random() * 0x100 >> 0),
utf8 : (level = 0) => new Uint8Array(new Array(Math.random() * 100 > 0).map(() => Math.random() * 0x100 >> 0))
};
const get_random = (level = -1) => {
const methods = Object.values(random);
return methods[Math.random() * methods.length >> 0](level + 1);
};
const encrypt_example = (example, show_only_errors) => {
const encrypted = anyanka_keys.encrypt(example),
decrypted = anyanka_keys.decrypt(encrypted),
json = [JSON.stringify(example), JSON.stringify(decrypted)];
if(json[0] != json[1])
console.error([example, encrypted, decrypted, ...json]);
else
show_only_errors || console.log([example, encrypted, decrypted], ...json);
};
const examples = {
a : () => [
[347234, 500000],
[[2342, 345, 12], 3000],
[[67, 200, 34,], 256]
].forEach(([example, base]) => {
const changed = {parameters : new AnyankaKeysBaseChangeParameters({from : base}), data : [], set : value => changed.data.unshift(value)},
returned = {parameters : new AnyankaKeysBaseChangeParameters({from : 58, to : base}), data : [], set : value => returned.data.unshift(value)};
AnyankaKeys.change_base_iteration(example, changed.set, changed.parameters);
changed.parameters.end(changed.set);
AnyankaKeys.change_base_iteration(changed.data, returned.set, returned.parameters);
returned.parameters.end(returned.set);
console.log([base, example, changed.data, returned.data]);
}),
b : () => [
// "PASA xD",
// ["PASA xD"],
// [45, 78, 134, 1, 1, 1],
// true,
// false,
// null,
// undefined,
// 783456,
33554432
].forEach(example => {
const encrypted = anyanka_keys.encrypt(example);
// console.log([example, "PASA"]);
const decrypted = anyanka_keys.decrypt(encrypted);
// console.log([example, [...example].map(character => [character, character.charCodeAt(0)]), encrypted, decrypted, decrypted.map(code => String.fromCharCode(code)).join("")]);
// console.log([example, [...example].map(character => [character, character.charCodeAt(0)]), encrypted, decrypted]);
console.log([example, encrypted, decrypted]);
}),
c : x => { // Absurdo.
x || (x = Math.random() * 100 >> 0);
while(x -- > 0){
const example = Math.random() * (1 << 28) >> 0,
changed = AnyankaKeys.change_base(example, 58, 1 << 28),
returned = AnyankaKeys.change_base(changed, 1 << 28, 58);
console.log([example, changed, returned]);
};
},
d : (x = null, show_only_errors = false) => {
x || (x = Math.random() * 100 >> 0);
while(x -- > 0){
const base = {
from : (Math.random() * (1 << 15) >> 0) + 2,
to : (Math.random() * (1 << 15) >> 0) + 2
},
example = new Array((Math.random() * 13 >> 0) + 3).fill(0).map((_, i) => {
let value = Math.random() * base.from >> 0;
if(!i && !value)
while(!(value = Math.random() * base.from >> 0));
return value;
}),
changed = AnyankaKeys.change_base(example, base.to, base.from),
returned = AnyankaKeys.change_base(changed, base.from, base.to);
if(example.some((value, i) => returned[i] != value))
console.error([base, example, changed, returned]);
else
show_only_errors || console.log([base, example, changed, returned]);
};
},
e : (x = null, show_only_errors = false) => {
x || (x = Math.random() * 100 >> 0);
while(x -- > 0){
const base = (Math.random() * 254 >> 0) + 2,
example = new Array((Math.random() * 61 >> 0) + 3).fill("").map((_, i) => {
let value = Math.random() * 256 >> 0;
if(!i && !value)
while(!(value = Math.random() * 256 >> 0));
return String.fromCharCode(value);
}).join(""),
changed = AnyankaKeys.change_base(example, base, 256),
returned = AnyankaKeys.change_base(changed, 256, base);
if(example != returned)
console.error([base, example, changed, returned]);
else
show_only_errors || console.log([base, example, changed, returned]);
};
},
f : () => {
const example = 783456;
let value = [783456, 0, 0],
i = 0;
AnyankaKeys.get_each_bytes(example, byte => {
console.log(byte);
value[1] += byte * 0x100 ** i;
value[2] = value[1] * 0x100 ** i + byte;
i ++;
});
console.log(value);
},
g : (show_only_errors = false) => running && setTimeout(() => {
console.log("PASA");
const example = get_random();
try{
const encrypted = anyanka_keys.encrypt(example),
decrypted = anyanka_keys.decrypt(encrypted),
json = [JSON.stringify(example), JSON.stringify(decrypted)]
if(json[0] != json[1])
console.error([example, encrypted, decrypted, ...json]);
else
show_only_errors || console.log([example, encrypted, decrypted], ...json);
examples.g(show_only_errors);
}catch(exception){
console.log(example);
console.error(exception);
};
}, timeout),
h : (show_only_errors = false) => running && setTimeout(() => {
console.log("PASA");
const example = random.integer(),
encrypted = anyanka_keys.encrypt(example),
decrypted = anyanka_keys.decrypt(encrypted),
json = [JSON.stringify(example), JSON.stringify(decrypted)];
if(json[0] != json[1])
console.error([example, encrypted, decrypted, ...json]);
else
show_only_errors || console.log([example, encrypted, decrypted], ...json);
examples.h(show_only_errors);
}, timeout),
stop : () => running = false,
bytes : (show_only_errors = false) => running && setTimeout(() => {
const example = random.bytes(),
encrypted = anyanka_keys.encrypt(example),
decrypted = anyanka_keys.decrypt(encrypted);
if(JSON.stringify(example) != JSON.stringify(decrypted))
console.error([JSON.stringify(example), encrypted, JSON.stringify(decrypted)]);
else
show_only_errors || console.log([JSON.stringify(example), encrypted, JSON.stringify(decrypted)]);
examples.bytes(show_only_errors);
}, timeout),
bytes_b : () => {
// const example = [131,187,55,219,94,25,18,170,132,212,189,200,188,212,64,50,120,112,37,155],
// const example = [],
const example = [0,191,24,6,173],
encrypted = anyanka_keys.encrypt(example),
decrypted = anyanka_keys.decrypt(encrypted);
// console.log([example.length, decrypted.length]);
console[
JSON.stringify(example) != JSON.stringify(decrypted) ? "error" : "log"
]([JSON.stringify(example), encrypted, JSON.stringify(decrypted)]);
},
// https://anyankakeys.local/tests
aa : show_only_errors => [
[205,204,187],
[29,167,216,222,216,244,130,137,226,110,151,180,244,251,164,136,55,196,183,145,219,118,25,57,209,172,233,137,42,248,217,247,114,34,39,120,154,5,223,21,145,213,141],
[244,36,219,121,175,198,233,43,156,74,121,199,113,226,33,21,217,103,226,186,80,245,82,186,51,49,26,135,35,43,143,241,111,138,188,102,11,99,20,162,63,199,53,170,42,103,242,9,127,130,76,156,218,246,117,245,95,25,205,214,55,201,232,237,100],
[228,253,25,186,36,216,62,182,189,128,37,44,221,45,125,58,253,32,122,54,245,193,99,117,89,8,53,109,26,43,49,46,58,223,67,84,146,206,118,31,174,5,29,122,98,92,74,159,153,163,252,91,142,243,160,234,242,64,105,150,139,241,179,129,79,60,69,176,12,245,115,13,225,105,222,7,67,28,248,27,88,135,50,49,210,4,205,239,243,171],
[86,76,16,5,7,37,86,111,65,203,77,6,92,44,244,153,45,66,29,7,134,193,4,244,85,200,143,41,142,218,13,93,186,215,221,126,56,60,17,252,57,188,126,148,22,204,49,110,237]
].forEach(example => encrypt_example(example, show_only_errors)),
ab : () => {
const start = Date.now();
[
{}, [], 0, "0", [0], 1, "1", [1], 2, "2", [3], 3,
[205,204,187],
[29,167,216,222,216,244,130,137,226,110,151,180,244,251,164,136,55,196,183,145,219,118,25,57,209,172,233,137,42,248,217,247,114,34,39,120,154,5,223,21,145,213,141],
[244,36,219,121,175,198,233,43,156,74,121,199,113,226,33,21,217,103,226,186,80,245,82,186,51,49,26,135,35,43,143,241,111,138,188,102,11,99,20,162,63,199,53,170,42,103,242,9,127,130,76,156,218,246,117,245,95,25,205,214,55,201,232,237,100],
[228,253,25,186,36,216,62,182,189,128,37,44,221,45,125,58,253,32,122,54,245,193,99,117,89,8,53,109,26,43,49,46,58,223,67,84,146,206,118,31,174,5,29,122,98,92,74,159,153,163,252,91,142,243,160,234,242,64,105,150,139,241,179,129,79,60,69,176,12,245,115,13,225,105,222,7,67,28,248,27,88,135,50,49,210,4,205,239,243,171],
[86,76,16,5,7,37,86,111,65,203,77,6,92,44,244,153,45,66,29,7,134,193,4,244,85,200,143,41,142,218,13,93,186,215,221,126,56,60,17,252,57,188,126,148,22,204,49,110,237]
].forEach(example => {
const start = Date.now(),
hash = anyanka_keys.hash(example),
end = Date.now();
console.log([start, hash, end, end - start, example]);
});
const end = Date.now();
console.log([start, end, end - start]);
},
ag : (show_only_errors = false) => running && setTimeout(() => {
const example = get_random(),
start = Date.now(),
hash = anyanka_keys.hash(example),
end = Date.now();
if(hash.length != 47)
console.error([start, hash, hash.length, end, end - start, example]);
else
console.log([start, hash, hash.length, end, end - start, example]);
examples.ag();
}, timeout),
ba : () => {
const ajax = new XMLHttpRequest();
ajax.open("get", "/tests/files/text.txt", true);
ajax.overrideMimeType("text/xml;charset=utf-8");
// ajax.overrideMimeType("text/xml;charset=UTF-8");
ajax.onreadystatechange = () => {
if(ajax.readyState == 4){
// const example = document.querySelector(".masive-text").innerText,
const example = ajax.responseText,
start = [Date.now(), 0, 0],
hash = anyanka_keys.hash(example),
end = [Date.now(), 0, 0];
start[1] = Date.now();
const encrypted = anyanka_keys.encrypt(example);
end[1] = Date.now();
start[2] = Date.now();
const decrypted = anyanka_keys.decrypt(encrypted);
end[2] = Date.now();
console.log(example.substring(0, 256));
console.log([start[0], hash, hash.length, end[0], end[0] - start[0], example.length]);
console.log([start[1], encrypted, encrypted.length, end[1], end[1] - start[1], example.length]);
console.log([start[2], decrypted, decrypted.length, end[2], end[2] - start[2], example.length]);
console.log([end[2] - start[1], end[2] - start[0], example == decrypted, decrypted.length]);
// [...decrypted].forEach((character, i) => character != example[i] && console.log([i, character, example[i]]));
};
};
ajax.send(null);
},
bb : example => {
const encrypted = anyanka_keys.encrypt(example || (example = random.string())),
decrypted = anyanka_keys.decrypt(encrypted);
console.log([example, encrypted, decrypted]);
}
};
anyanka_keys.set_public_key("fFRjQ8vrphUmJ517uithMT7vtj6pK5BrtSqQvpgtovdG297iVBADHuazcf7s25WEdy37wXJWxS7zmREe1yPY3M5obAaEbJV9Gc5WNCeJUQTFswe4ajNmkDebg81jqiLb1CGja83tSU5PFSPwF1NZWb7F3fPUZuZh7WToTyz2sc875Y5fAJTGsbBCBbwvTW4ZViRgZ25fe3rqgnDJ29FCmDSKwnfcWVLBcoESCEoaw8DkYQLJwdJAhsof5FsfnxdR");
// ["a", "b"].forEach(key => examples[key]());
// ["c"].forEach(key => examples[key]());
// ["d"].forEach(key => examples[key](1000, true));
// ["e"].forEach(key => examples[key](1000, true));
// examples.b();
// examples.f();
examples.g(true);
// examples.bytes(false);
// examples.bytes_b();
// examples.h(true);
// setTimeout(() => running = false, 5000);
// examples.aa();
// examples.ab();
// examples.ag();
// examples.ba();
// examples.bb("KyMAN cuesta 239€, \u0016, joder.");
// console.log("€".charCodeAt(0));
// console.log(String.fromCharCode(92));
// console.log(anyanka_keys.get_public_key());
</script>
</head>
<body></body>
</html>