Created
May 21, 2019 23:44
-
-
Save ianfabs/7566d4b14cd1e2459818045bcc52a08a to your computer and use it in GitHub Desktop.
Zero-width char exploit
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 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