hiddencoder
Advanced tools
Comparing version 1.0.5 to 1.0.6
@@ -5,3 +5,3 @@ /** | ||
const {h2a} = require('hiddencoder'); | ||
const {h2a} = require('../src/index'); | ||
const fs = require('fs'); | ||
@@ -8,0 +8,0 @@ |
@@ -5,3 +5,3 @@ /** | ||
const {a2h} = require('hiddencoder'); | ||
const {a2h} = require('../src/index'); | ||
const fs = require('fs'); | ||
@@ -8,0 +8,0 @@ |
{ | ||
"name": "hiddencoder", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"description": "Encode ASCII strings into zero-width unicode characters, and decode back into ASCII", | ||
"main": "src/index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "node tests/tests.js" | ||
}, | ||
@@ -9,0 +9,0 @@ "repository": { |
# Hiddencoder | ||
Encode ASCII strings into zero-width unicode characters, and decode back into ASCII | ||
Encode ASCII strings into zero-width unicode characters (hiddencoded), and decode back into ASCII | ||
## Description | ||
A simple encode-decode tool. | ||
Got the idea from [@FakeUnicode](https://twitter.com/FakeUnicode)'s [tweet](https://twitter.com/FakeUnicode/status/882419542990831616). | ||
Got the idea from [@FakeUnicode](https://twitter.com/FakeUnicode)'s [tweet](https://twitter.com/FakeUnicode/status/882419542990831616), and the great breakdown on [Stefan Judis' blog post](https://www.stefanjudis.com/blog/hidden-messages-in-javascript-property-names/). | ||
This tool takes an ASCII string and encodes it into zero-width unicode characters, which won't show up when printing the unescaped string. | ||
This tool takes an ASCII string and encodes it into zero-width unicode characters, which won't show up when printing the unescaped string (a hiddencoded string). | ||
A decode operation is also available. | ||
@@ -19,4 +19,4 @@ | ||
// Output: | ||
// Hidden: 󠄳 | ||
// Actual: Hidden message | ||
// Hidden: 󠅈󠅩󠅤󠅤󠅥󠅮󠄠󠅳󠅴󠅲󠅩󠅮󠅧 <- It's right here, the empty character | ||
// Actual: Hidden string | ||
``` | ||
@@ -37,2 +37,2 @@ | ||
``` | ||
This will save the decoded output into [`encode.js.enc.dec`](example/encode.js.enc.dec) | ||
This will save the decoded output into [`encode.js.enc.dec`](example/encode.js.enc.dec) |
/* | ||
Hiddencoder | ||
Encode ASCII strings into zero-width unicode characters, and decode back into ASCII | ||
Encode ASCII strings into zero-width unicode characters (hiddencoded), and decode back into ASCII | ||
*/ | ||
const alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890!@#$%^&*(),.`~-=?\\/<>;:[]{}"_+|\n\r\t ' + "'"; | ||
const hidingChars = '%uDB40%uD'; | ||
const initValue = 65; // Use 65 ('A') to avoid having values > 100 or < -100 | ||
const CODES = {}; | ||
for (const c of alphabet) { | ||
const charPoint = c.codePointAt(0); | ||
const pointDiff = initValue - c.codePointAt(0); | ||
let u = pointDiff < 0 ? 'C' : 'D'; | ||
const val = '' + Math.abs(pointDiff); | ||
u += (val.length < 2 ? '0' : '') + val | ||
CODES[charPoint] = unescape(u); | ||
CODES[unescape(u)] = charPoint; | ||
} | ||
const unicodePrefix = '%uDB40%uDD'; // An invalid zero-width character followed by the beginning of a unicode for another zero-width character | ||
/** | ||
* ASCII 2 Hiddencoded | ||
* Encode ASCII chars to hidden string | ||
@@ -24,10 +14,9 @@ * @param {string} inputAscii | ||
function a2h(inputAscii) { | ||
let output = ''; | ||
for (const c of inputAscii) { | ||
output += unescape(hidingChars + CODES[c.codePointAt(0)]); | ||
} | ||
return output | ||
// Convert each char's code point to hex and append it to the unicodePrefix | ||
// If the hex is smaller than 10, pad it with 0 on the left | ||
return [...inputAscii].reduce((output, c) => output += (unescape(unicodePrefix + ('' + c.codePointAt(0).toString(16)).padStart(2, '0'))), ''); | ||
} | ||
/** | ||
* Hiddencoded 2 ASCII | ||
* Decode hidden strings back to ASCII | ||
@@ -37,9 +26,4 @@ * @param {string} inputHidden | ||
function h2a(inputHidden) { | ||
let output = ''; | ||
const hiddenCode = escape(inputHidden).split(hidingChars); | ||
for (const c of hiddenCode) { | ||
if (!c) continue; | ||
output += String.fromCodePoint(CODES[c]); | ||
} | ||
return output; | ||
// Skip the first item in the array since it'll be empty | ||
return escape(inputHidden).split(unicodePrefix).slice(1).reduce((output, c) => output += (String.fromCodePoint(parseInt(c, 16))), ''); | ||
} | ||
@@ -46,0 +30,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
6624
9
0
37
57