Be careful what you copy: Invisibly inserting usernames into text with Zero-Width Characters

It certainly can do, and you would have no idea

Why?

How?

Fingerprinting the 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 '​'; // zero-width space
} else if (num === 0) {
return '‌'; // zero-width non-joiner
}
return '‍'; // zero-width joiner
}).join('') // zero-width no-break space
);

Extracting the username from the fingerprinted text

const zeroWidthToBinary = string => (
string.split('').map((char) => { // zero-width no-break space
if (char === '​') { // zero-width space
return '1';
} else if (char === '‌') { // zero-width non-joiner
return '0';
}
return ' '; // add single space
}).join('')
);
const binaryToText = string => (
string.split(' ').map(num =>
String.fromCharCode(parseInt(num, 2))).join('')
);

Conclusion

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store