Created
June 22, 2020 14:15
-
-
Save TPXP/543f4feb9a6aa3142db96e8e525018ee to your computer and use it in GitHub Desktop.
PHPass 64-encoding conversion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const phpassbase64 = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; | |
const base64translate = (input) => { | |
const res = [0]; | |
let currentBit = 0, index = 0; | |
input.split('').forEach(l => { | |
const i = phpassbase64.indexOf(l); | |
res[index] += (i << currentBit) & 0xff; | |
currentBit += 6; | |
if(currentBit >= 8) { | |
currentBit -= 8; | |
index++; | |
res.push(i >> (6-currentBit)); | |
} | |
}); | |
if(res[res.length - 1] === 0) | |
res.pop(); | |
return Buffer.from(res); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment