Skip to content

Instantly share code, notes, and snippets.

@TPXP
Created June 22, 2020 14:15
Show Gist options
  • Save TPXP/543f4feb9a6aa3142db96e8e525018ee to your computer and use it in GitHub Desktop.
Save TPXP/543f4feb9a6aa3142db96e8e525018ee to your computer and use it in GitHub Desktop.
PHPass 64-encoding conversion
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