UNPKG

bcryption

Version:

Bcryption is a simple digital encription algorithm, is stable for javascript

53 lines (51 loc) 2.45 kB
const secretManipulator = require("./secretManipulator") const passwordManipulator = require('./passwordManipulator') async function num2Hex(num) { let arrayedNumber = num.match(/.{1,4}/g) ?? []; let HexString = "" await arrayedNumber.map((val) => { HexString += parseInt(val).toString(16).padStart(4, 0) }) return HexString } async function encripter(inputString, SECRET) { const { ENC_SUM, SECRET_KEY_LENGTH } = secretManipulator(SECRET) const { STABLE, PASSWORD_LENGTH } = passwordManipulator(inputString, 1) let cipherString, conAscii = "1111"; let theSumOf2 = (ENC_SUM * PASSWORD_LENGTH) + SECRET_KEY_LENGTH await inputString.split('').map((char, index) => { if (theSumOf2 % 9 == 0) { let letter = (char.charCodeAt(0) * (theSumOf2 / 9) + index).toString().padStart(8, 0); conAscii += "" + letter } else if (theSumOf2 % 8 == 0) { let letter = (char.charCodeAt(0) * (theSumOf2 / 8) + index).toString().padStart(8, 0); conAscii += "" + letter } else if (theSumOf2 % 7 == 0) { let letter = (char.charCodeAt(0) * (theSumOf2 / 7) + index).toString().padStart(8, 0); conAscii += "" + letter } else if (theSumOf2 % 6 == 0) { let letter = (char.charCodeAt(0) * (theSumOf2 / 6) + index).toString().padStart(8, 0); conAscii += "" + letter } else if (theSumOf2 % 5 == 0) { let letter = (char.charCodeAt(0) * (theSumOf2 / 5) + index).toString().padStart(8, 0); conAscii += "" + letter } else if (theSumOf2 % 4 == 0) { let letter = (char.charCodeAt(0) * (theSumOf2 / 4) + index).toString().padStart(8, 0); conAscii += "" + letter } else if (theSumOf2 % 3 == 0) { let letter = (char.charCodeAt(0) * (theSumOf2 / 3) + index).toString().padStart(8, 0); conAscii += "" + letter } else if (theSumOf2 % 2 == 0) { let letter = (char.charCodeAt(0) * (theSumOf2 / 2) + index).toString().padStart(8, 0); conAscii += "" + letter } else { let letter = (char.charCodeAt(0) * theSumOf2).toString().padStart(8, 0); conAscii += "" + letter } }) await num2Hex(conAscii).then((res) => { cipherString = res }) return cipherString; } module.exports = encripter;