Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hiddencoder

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hiddencoder - npm Package Compare versions

Comparing version 1.0.5 to 1.0.6

example/encode.js.enc

2

example/decode.js

@@ -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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc