Skip to content

Instantly share code, notes, and snippets.

@ianfabs
Created May 21, 2019 23:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ianfabs/7566d4b14cd1e2459818045bcc52a08a to your computer and use it in GitHub Desktop.
Save ianfabs/7566d4b14cd1e2459818045bcc52a08a to your computer and use it in GitHub Desktop.
Zero-width char exploit
const toZW = (text) => {
const zeroPad = num => '00000000'.slice(String(num).length) + num;
const textToBinary = username => (
username.split('').map(char => zeroPad(char.charCodeAt(0).toString(2))).join(' ')
);
const binaryToZeroWidth = binary => (
binary.split('').map((binaryNum) => {
const num = parseInt(binaryNum, 10);
if (num === 1) {
return ''; // invisible ​
} else if (num === 0) {
return ''; // invisible ‌
}
return '‍'; // invisible ‍
}).join('') // invisible 
);
const binaryUsername = textToBinary(username);
const zeroWidthUsername = binaryToZeroWidth(binaryUsername);
return zeroWidthUsername;
}
console.log( "'" + toZW('ls') + "'" );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment