fmt
This commit is contained in:
parent
06dfe5ffb6
commit
6852522570
2 changed files with 67 additions and 63 deletions
|
|
@ -1,18 +1,20 @@
|
|||
import { assertEquals } from "https://deno.land/std@0.122.0/testing/asserts.ts";
|
||||
import {EnchantrixEntropyQuasi} from "./quasi.ts";
|
||||
import { EnchantrixEntropyQuasi } from "./quasi.ts";
|
||||
|
||||
// Compact form: name and function
|
||||
Deno.test("IN: Snider OUT: r3dinS", () => {
|
||||
const x = new EnchantrixSaltQuasiEntropy('Snider').salty();
|
||||
assertEquals(x, 'r3dinS');
|
||||
const x = new EnchantrixSaltQuasiEntropy("Snider").salty();
|
||||
assertEquals(x, "r3dinS");
|
||||
});
|
||||
// Compact form: name and function
|
||||
Deno.test("IN: snider OUT: r3dinz", () => {
|
||||
const x = new EnchantrixSaltQuasiEntropy('snider').salty();
|
||||
assertEquals(x, 'r3dinz');
|
||||
const x = new EnchantrixSaltQuasiEntropy("snider").salty();
|
||||
assertEquals(x, "r3dinz");
|
||||
});
|
||||
|
||||
Deno.test("IN: a long string with spaces and workds and much letters and stuff OUT: ffu7zdn4zr37731hcumdn4zdkr0wdn4z3c4pzh7iwgnir7zgn014", () => {
|
||||
const x = new EnchantrixSaltQuasiEntropy('a long string with spaces and workds and much letters and stuff').salty();
|
||||
assertEquals(x, 'ffu7zdn4zr37731hcumdn4zdkr0wdn4z3c4pzh7iwgnir7zgn014');
|
||||
const x = new EnchantrixSaltQuasiEntropy(
|
||||
"a long string with spaces and workds and much letters and stuff",
|
||||
).salty();
|
||||
assertEquals(x, "ffu7zdn4zr37731hcumdn4zdkr0wdn4z3c4pzh7iwgnir7zgn014");
|
||||
});
|
||||
|
|
|
|||
|
|
@ -2,68 +2,70 @@
|
|||
* Reproducible salts from input without prior knowledge
|
||||
*/
|
||||
export class EnchantrixEntropyQuasi {
|
||||
/**
|
||||
* Extend to enforce a custom mapping
|
||||
*
|
||||
* @protected
|
||||
*/
|
||||
// deno-lint-ignore no-explicit-any
|
||||
protected charMap: any = {
|
||||
" ": "",
|
||||
"o": "0",
|
||||
"l": "1",
|
||||
"e": "3",
|
||||
"a": "4",
|
||||
"s": "z",
|
||||
"t": "7",
|
||||
};
|
||||
|
||||
/**
|
||||
* Extend to enforce a custom mapping
|
||||
*
|
||||
* @protected
|
||||
*/
|
||||
// deno-lint-ignore no-explicit-any
|
||||
protected charMap:any = {
|
||||
' ': '',
|
||||
'o': '0',
|
||||
'l': "1",
|
||||
'e': "3",
|
||||
'a': "4",
|
||||
's': "z",
|
||||
't': "7",
|
||||
}
|
||||
/**
|
||||
* @type {string} Origin Input
|
||||
* @protected
|
||||
*/
|
||||
protected readonly _input: string = "";
|
||||
|
||||
/**
|
||||
* @type {string} Origin Input
|
||||
* @protected
|
||||
*/
|
||||
protected readonly _input: string = ''
|
||||
/**
|
||||
* Initiate with input to work on
|
||||
*
|
||||
* @param input
|
||||
*/
|
||||
constructor(input: string) {
|
||||
this._input = input;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initiate with input to work on
|
||||
*
|
||||
* @param input
|
||||
*/
|
||||
constructor(input: string) {
|
||||
this._input = input
|
||||
}
|
||||
/**
|
||||
* Returns CharMap
|
||||
*
|
||||
* @returns {{'[char]': string}}
|
||||
*/
|
||||
// deno-lint-ignore no-explicit-any
|
||||
get keyMap(): any {
|
||||
return this.charMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns CharMap
|
||||
*
|
||||
* @returns {{'[char]': string}}
|
||||
*/
|
||||
// deno-lint-ignore no-explicit-any
|
||||
get keyMap():any {
|
||||
return this.charMap
|
||||
}
|
||||
/**
|
||||
* Performs salt on input
|
||||
*
|
||||
* @returns {string} Salted Input
|
||||
*/
|
||||
salty(): string {
|
||||
if (!this._input) {
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs salt on input
|
||||
*
|
||||
* @returns {string} Salted Input
|
||||
*/
|
||||
salty(): string {
|
||||
if (!this._input) {
|
||||
return '';
|
||||
}
|
||||
let i: number = this._input.length;
|
||||
|
||||
let i: number = this._input.length
|
||||
const salt: string[] = [];
|
||||
|
||||
const salt:string[] = []
|
||||
|
||||
while (i--) {
|
||||
// If Char is in the map, use the replaced value; otherwise use original char
|
||||
salt.push(this.keyMap[this._input[i]] !== undefined ? this.keyMap[this._input[i]] : this._input[i])
|
||||
}
|
||||
|
||||
return salt.join('')
|
||||
}
|
||||
while (i--) {
|
||||
// If Char is in the map, use the replaced value; otherwise use original char
|
||||
salt.push(
|
||||
this.keyMap[this._input[i]] !== undefined
|
||||
? this.keyMap[this._input[i]]
|
||||
: this._input[i],
|
||||
);
|
||||
}
|
||||
|
||||
return salt.join("");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue