UNPKG

pwd-enc

Version:

Password encryption

71 lines (58 loc) 2.45 kB
var stringData = "abcdefghijklmnopqrst uvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-=[];',./!@#$%^&*()_+{}:\"<>?"; var encriptData1 = "klmnopqrstuvwxyzABCD EFGHIJKLMNOPQRSTUVWXYZ1234567890-=[];',./!@#$%^&*()_+{}:\"<>?abcdefghij"; var encriptData2 = "QRSTUVWXYZ1234567890 -=[];',./!@#$%^&*()_+{}:\"<>?abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOP"; var dec = (encryptPassword, encriptData, stringData) => { var password=""; for (let index = 0; index < encryptPassword.length; index++) { const element = encryptPassword[index]; for (let index1 = 0; index1 < encriptData.length; index1++) { const element1 = encriptData[index1]; if (element == element1) { password = password + stringData[index1] } } } return password; } var enc = (password, stringData, encriptData) => { var encryptPassword=""; for (let index = 0; index < password.length; index++) { const element = password[index]; for (let index1 = 0; index1 < stringData.length; index1++) { const element1 = stringData[index1]; if (element == element1) { encryptPassword = encryptPassword + encriptData[index1] } } } return encryptPassword; } exports.EncryptPassword = (password) => { if (password) { password = password.split(""); var encryptPassword1 = enc(password, stringData, encriptData1) var encryptPassword2 = enc(password, stringData, encriptData2) return encryptPassword1 + encryptPassword2 } else { return password; } } exports.DecryptPassword = (encryptPassword) => { if (encryptPassword) { var length = encryptPassword.length; var encryptPassword1 = encryptPassword.substr(0, encryptPassword.length/2); var encryptPassword2 = encryptPassword.substr(encryptPassword.length/2, encryptPassword.length); encryptPassword = encryptPassword.split(""); var password1 = dec(encryptPassword1, encriptData1, stringData); var password2 = dec(encryptPassword2, encriptData2, stringData); if(password1 == password2) { return password1; } else { return "Invalid Password" } } else { return encryptPassword; } } //console.log("ENC PWD---->" + EncryptPassword("Karthik")) //console.log("DCP PWD---->" + DecryptPassword("UkBDrsu*Q80XY1"))