Enchantrix/vault/lib/entropy/quasi.ts
google-labs-jules[bot] c1434a45ce feat: Port crypt library from Core
This commit ports the crypt library from the Core repository to the Enchantrix repository. It includes the following changes:

- The project is now a Go module.
- The `lthn` and `crypt` packages have been ported from the Core repository.
- The PGP functionality has been commented out pending resolution of dependency issues.
- The old Deno project has been moved to the `vault` directory.
- The README has been updated to reflect the new project structure.
2025-10-30 17:11:31 +00:00

67 lines
1.1 KiB
TypeScript

import {createHash} from '../../deps.ts';
/**
* Reproducible salts from input without prior knowledge
*/
export class EnchantrixEntropyQuasi {
constructor() {
}
/**
* 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'
};
static get keyMap(): any {
return this._keyMap;
}
static set keyMap(val) {
this._keyMap = val;
}
static changeKeyMap(map: any) {
return this.keyMap(map);
}
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('');
}
}