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

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

SOLID — common misunderstandings (Part 1: Introduction & SRP)

ChainSwap Hacking Event Handling and TSHP Token Compensation Plan

Building a self-testing application

How to Convert EML to PNG in Swift

Managing Your Scene in Unity

Connecting your Cellphone to Microsoft Azure IoT Central

Command And Query: Domain (2)

If Programming Languages Were Disney Characters

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
Tom Ross

Tom Ross

More from Medium

Top 5 Reasons To Use Godot

Rose with the Godot logo in the center.

Feeds Fetcher — Drupal

Making WebSocket connection using fastify:

How to Install Google Chrome 98 in Ubuntu / Rocky Linux & Fedora