updates hash function to lastest.
This commit is contained in:
parent
b268768c36
commit
ff59745c7d
3 changed files with 59 additions and 58 deletions
2
deps.ts
Normal file
2
deps.ts
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
|
||||
export { createHash } from "https://deno.land/std@0.77.0/hash/mod.ts";
|
||||
|
|
@ -1,71 +1,67 @@
|
|||
import {createHash} from '../../deps.ts';
|
||||
|
||||
/**
|
||||
* 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",
|
||||
};
|
||||
|
||||
/**
|
||||
* @type {string} Origin Input
|
||||
* @protected
|
||||
*/
|
||||
protected readonly _input: string = "";
|
||||
|
||||
/**
|
||||
* Initiate with input to work on
|
||||
*
|
||||
* @param input
|
||||
*/
|
||||
constructor(input: string) {
|
||||
this._input = input;
|
||||
}
|
||||
constructor() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns CharMap
|
||||
*
|
||||
* @returns {{'[char]': string}}
|
||||
*/
|
||||
// deno-lint-ignore no-explicit-any
|
||||
get keyMap(): any {
|
||||
return this.charMap;
|
||||
}
|
||||
/**
|
||||
* Holds the defult mapping swaps
|
||||
* @private
|
||||
*/
|
||||
protected static _keyMap = {
|
||||
'o': '0',
|
||||
'l': '1',
|
||||
'e': '3',
|
||||
'a': '4',
|
||||
's': 'z',
|
||||
't': '7',
|
||||
'0': 'o',
|
||||
'1': 'l',
|
||||
'3': 'e',
|
||||
'4': 'a',
|
||||
'7': 't'
|
||||
};
|
||||
|
||||
/**
|
||||
* Performs salt on input
|
||||
*
|
||||
* @returns {string} Salted Input
|
||||
*/
|
||||
salty(): string {
|
||||
if (!this._input) {
|
||||
return "";
|
||||
}
|
||||
static get keyMap(): any {
|
||||
return this._keyMap;
|
||||
}
|
||||
|
||||
let i: number = this._input.length;
|
||||
static set keyMap(val) {
|
||||
this._keyMap = val;
|
||||
}
|
||||
|
||||
const salt: string[] = [];
|
||||
static changeKeyMap(map: any) {
|
||||
return this.keyMap(map);
|
||||
}
|
||||
|
||||
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],
|
||||
);
|
||||
}
|
||||
static hash(input: string): string {
|
||||
return createHash('sha256')
|
||||
.update(input + this.createSalt(input))
|
||||
.toString() as string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a quasi-salt from a string.
|
||||
* @param input The input string.
|
||||
*/
|
||||
static createSalt(input: string): string {
|
||||
if (!input) {
|
||||
return '';
|
||||
}
|
||||
|
||||
let i: number = input.length;
|
||||
let salt: string[] = [];
|
||||
while (i--) {
|
||||
const char: string = input[i];
|
||||
salt.push(this.keyMap[char] !== undefined ? this.keyMap[char] : char);
|
||||
}
|
||||
|
||||
return salt.join('');
|
||||
}
|
||||
|
||||
return salt.join("");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,9 @@ import { assertEquals } from "https://deno.land/std@0.122.0/testing/asserts.ts";
|
|||
import { EnchantrixParseFile } from "./file.ts";
|
||||
|
||||
// Compact form: name and function
|
||||
//
|
||||
// where "snider" is the mapping and "r3dinS" is the binary return.
|
||||
//
|
||||
Deno.test("IN: Snider OUT: r3dinS", () => {
|
||||
const x = new EnchantrixParseFile(".dataset/Dont-Panic.webp").load();
|
||||
assertEquals(x, "r3dinS");
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue