Skip to content

zachmargolis/obfuscate.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

obfuscate.js

Obfuscate the crap out of strings in Javascript!

Basically, my homegrown, not-as-complete version of jsfuck.

  1. Background
  2. Usage
  3. API

Background

Javascript has some crazy type coersion. Here's a few quick examples below, and check out Gary Bernhardt's WAT talk for a fun walkthrough. There are some nice explanations on StackOverflow.

> []+{}
0
> {}+[]
'[object Object]'

Usage

Anyways, we can take advantage of these coercesions for some crazy obfuscation:

> var obfuscate = require('obfuscate');

> obfuscate('Hello world!')
'[]+([])+"H"+[]+([])+([]+(!![]))[!+[]+!+[]+!+[]]+((![])+[])[!+[]+!+[]]+((![])+[])[!+[]+!+[]]+([]+{})[[]-[]+!+[]]+([]+{})[!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]]+[]+[]+"w"+[]+[]+[[]]+([]+{})[[]-[]+!+[]]+([]+(!![]))[[]-[]+!+[]]+((![])+[])[!+[]+!+[]]+([][[]]+[])[!+[]+!+[]]+[]+[]+"!"+[]+[]+[[]]+[[[]]]'

> []+([])+"H"+[]+([])+([]+(!![]))[!+[]+!+[]+!+[]]+((![])+[])[!+[]+!+[]]+((![])+[])[!+[]+!+[]]+([]+{})[[]-[]+!+[]]+([]+{})[!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]]+[]+[]+"w"+[]+[]+[[]]+([]+{})[[]-[]+!+[]]+([]+(!![]))[[]-[]+!+[]]+((![])+[])[!+[]+!+[]]+([][[]]+[])[!+[]+!+[]]+[]+[]+"!"+[]+[]+[[]]+[[[]]]
'Hello world!'

Happy obfuscating!

API

# obfuscate(str)

Obfuscates a string by creating an expression that evaluates to that string.

> obfuscate('t')
'([]+(!![]))[[]-[]]'

# obfuscate.chr(str)

Obfuscates a character by creating an expression that evaluates to that character (string).

> obfuscate.chr('[')
'([]+{})[[]-[]]'

# obfuscate.num(num, [highPrecedence])

Creates an expression that evaluates to that number. Has an optional parameter highPrecedence that makes the resulting expression take higher precedence, especially useful inside brackets

> obfuscate.num(1)
'!+[]'
> obfuscate.num(1, true)
'[]-[]+!+[]'

# obfuscate.emptyString([num])

Creates a expression that evaluates to the empty string. For variety, a num parameter can add additional terms.

> obfuscate.emptyString(0)
'[]+([])'

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published