Obfuscate the crap out of strings in Javascript!
Basically, my homegrown, not-as-complete version of jsfuck.
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]'
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!
# 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)
'[]+([])'