首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >WTF.js混淆器

WTF.js混淆器
EN

Code Golf用户
提问于 2020-01-24 18:35:17
回答 2查看 7.4K关注 0票数 30

背景

javascript的一个常见的模因方面是它极其松散的类型强制,它允许+!![]+[+[]] == '10',这种技术也可以用于创建字母,如下面的示例所示:

代码语言:javascript
复制
[[][[]]+[]][+[]][-~[]] == 'n'
[undefined+[]][+[]][-~[]] // [][[]] -> undefined
['undefined'][+[]][-~[]]  // undefined+[] -> 'undefined'
['undefined'][0][-~[]]    // +[] -> 0
'undefined'[-~[]]         // ['undefined'][0] -> 'undefined'
'undefined'[1]            // -~[] -> -(-1) -> 1
'n'

js矫顽力的一些例子:

代码语言:javascript
复制
[][[]] = undefined        // out of bounds array access returns undefined
+[][[]] = NaN             // the unary + operator coerces to numbers +undefined is NaN
+[] = 0                   // empty arrays coerce to the number 0
~[]/[] = -Infinity        // ~ coerces any value to a number then does bitwise negation and / coerces the second value to a number
[]+{} = '[Object object]' // plus coerces both values into strings if it can't do numeric addition
![] = false               // ! coerces empty arrays to false
!![] = true               // negation of previous coercion
+!![] = 1                 // number coercion of true
-~[] = 1                  // ~ coerces [] to 0 and the bitwise negation of 0 is -1, -(-1)=1
true+[] = 'true'          // adding an empty array to a primitive coerces it to a string
'true'[+[]] = 't'         // strings are treated as arrays by js
'true'[-~[]] = 'r'

以下是使用不同操作符的js矫顽器的引用表

注意:表格中的蓝色阴影单元格是字符串,而黄色单元格是文字。

任务

给定一个只有字母abcdefijlnorstuy的字符串,将其转换为只包含计算为原始字符串的字符[]+-~/{}!的有效javascript。请注意,这不是JSFuck,而是完全集中在可以(相对地)简洁翻译的字符串子集上。

输入

可以用字母abcdefijlnorstuy (可以包括空格)写的任何小写字符串

输出

有效的javascript只包含将在js环境中计算为原始单词的字符[]+-~/{}!

示例

代码语言:javascript
复制
f('u') -> [[][[]]+[]][+[]][+[]]

f('a') -> [+[][[]]+[]][+[]][-~[]]

f('t') -> [-~[]/[]+[]][+[]][-~[]-~[]-~[]-~[]-~[]-~[]]

f('o') -> [[]+{}][+[]][-~[]]

f('l') -> [![]+[]][+[]][-~[]-~[]]

f('r') -> [!![]+[]][+[]][-~[]]

f('defined') -> [[][[]]+[]][+[]][-~[]-~[]]+[[][[]]+[]][+[]][-~[]-~[]-~[]]+[[][[]
]+[]][+[]][-~[]-~[]-~[]-~[]]+[[][[]]+[]][+[]][-~[]-~[]-~[]-~[]-~[]]+[[][[]]+[]][
+[]][-~[]]+[[][[]]+[]][+[]][-~[]-~[]-~[]]+[[][[]]+[]][+[]][-~[]-~[]]

f('aurora borealis') -> [+[][[]]+[]][+[]][-~[]]+[[][[]]+[]][+[]][+[]]+[!![]+[]][
+[]][-~[]]+[[]+{}][+[]][-~[]]+[!![]+[]][+[]][-~[]]+[+[][[]]+[]][+[]][-~[]]+[[]+{
}][+[]][-~[]-~[]-~[]-~[]-~[]-~[]-~[]]+[[]+{}][+[]][-~[]-~[]]+[[]+{}][+[]][-~[]]+
[!![]+[]][+[]][-~[]]+[[][[]]+[]][+[]][-~[]-~[]-~[]]+[+[][[]]+[]][+[]][-~[]]+[![]
+[]][+[]][-~[]-~[]]+[[][[]]+[]][+[]][-~[]-~[]-~[]-~[]-~[]]+[![]+[]][+[]][-~[]-~[
]-~[]]

f('code tennis') -> [[]+{}][+[]][-~[]-~[]-~[]-~[]-~[]]+[[]+{}][+[]][-~[]]+[[][[]
]+[]][+[]][-~[]-~[]]+[[][[]]+[]][+[]][-~[]-~[]-~[]]+[[]+{}][+[]][-~[]-~[]-~[]-~[
]-~[]-~[]-~[]]+[-~[]/[]+[]][+[]][-~[]-~[]-~[]-~[]-~[]-~[]]+[[][[]]+[]][+[]][-~[]
-~[]-~[]]+[[][[]]+[]][+[]][-~[]]+[[][[]]+[]][+[]][-~[]]+[[][[]]+[]][+[]][-~[]-~[
]-~[]-~[]-~[]]+[![]+[]][+[]][-~[]-~[]-~[]]

f('js bad') -> [[]+{}][+[]][-~[]-~[]-~[]]+[![]+[]][+[]][-~[]-~[]-~[]]+[[]+{}][+[
]][-~[]-~[]-~[]-~[]-~[]-~[]-~[]]+[[]+{}][+[]][-~[]-~[]]+[+[][[]]+[]][+[]][-~[]]+
[[][[]]+[]][+[]][-~[]-~[]]

f('obfuscate') -> [[]+{}][+[]][-~[]]+[[]+{}][+[]][-~[]-~[]]+[[][[]]+[]][+[]][-~[
]-~[]-~[]-~[]]+[[][[]]+[]][+[]][+[]]+[![]+[]][+[]][-~[]-~[]-~[]]+[[]+{}][+[]][-~
[]-~[]-~[]-~[]-~[]]+[+[][[]]+[]][+[]][-~[]]+[-~[]/[]+[]][+[]][-~[]-~[]-~[]-~[]-~
[]-~[]]+[[][[]]+[]][+[]][-~[]-~[]-~[]]

规则

最低字节数获胜。

解决方案可以用任何语言编写,但是生成的代码必须在chrome、firefox或node.js repl中进行计算。

不要滥用任何常见的漏洞。

EN

回答 2

Code Golf用户

发布于 2020-01-25 04:55:17

Prolog (SWI),269字节

这不是一个特别短的解决方案,但使这个挑战有趣,因为它能够使用回溯自动选择哪个字符串和索引到该字符串中使用的每个字符。

代码语言:javascript
复制
`fals`^`![]+[]`.
`[object `^`[]+{}`.
`und`^`[][[]]+[]`.
`-Infinity`^`~[]/[]+[]`.
`tr`^`!![]+[]`.
[]-`[]`.
[H|T]-S:-B^C,nth0(I,B,H),length(L,I),foldl([_,V]>>append(`-~[]+`,V),L,` +[]`,J),T-U,append([`[`,C,`][+[]][`,J,`]+`,U],S).
S/W:-S+A,A-B,W+B.
A+B:-string_codes(A,B).

在网上试试!

未高尔夫球码

代码语言:javascript
复制
% Declaration of strings we can generate with their corresponding JS.
base_str(`undefined`,`[[][[]]+[]][+[]]`).
base_str(`[object Object]`, `[]+{}`).
base_str(`Infinity`, `[-~[]/[]+[]][+[]]`).
base_str(`NaN`, `[+[][[]]+[]][+[]]`).
base_str(`true`, `!![]+[]`).
base_str(`false`, `![]+[]`).

% Construct JS used to index into strings
wtf_index(0,`+[]`).
wtf_index(1,`-~[]`).
wtf_index(N, S0) :-
  N > 1,
  wtf_index(1, S1),
  M is N - 1,
  wtf_index(M, S2),
  append([S1,`+`,S2],S0).

% Construct JS used for single char
wtf_char(C, WC) :-

  % Find known string with desired character at some index
  base_str(S, WS),
  nth0(I, S, C),

  % JS for this index
  wtf_index(I, WI),

  % JS to select index from string
  append([`(`,WS,`)[`,WI,`]`],WC).

% Map wtf_char over string, reducing to single string
wtf_list([], `[]`).
wtf_list([H|T], WS) :-
  wtf_char(H, WH),
  wtf_list(T, WT),
  append(WH, [0'+|WT], WS).

wtf_str(S, W) :-
  string_codes(S, SC),
  wtf_list(SC, WC),
  string_codes(W, WC).
票数 8
EN

Code Golf用户

发布于 2020-01-25 11:40:04

木炭,95字节

代码语言:javascript
复制
≔⪪“<≦ω≕ε…(Bς´B⌈YWγ№Φξ⌕IY¦l ”,ηFS«≔⊟Φ⁵№§ηκιζ⊞υ⪫[]⁺⁺§⪪“"∧|⌊AuüQ⁷~⊙<⁷≕u?ψμ”,ζ×+[]][²×-~[]⌕§ηζι»⪫υ+

在网上试试!链接是详细的代码版本。解释:

代码语言:javascript
复制
≔⪪“<≦ω≕ε…(Bς´B⌈YWγ№Φξ⌕IY¦l ”,η

在逗号上拆分压缩字符串"\n\nd,\nals,\nru,\\nnfi\n\n\ny,\nobject "。这是数组["undefined", "false", "true", "Infinity", "[object Object]"],只保留空格和唯一的字母,并在最后一个剩余字母处截断以提高压缩效果。

代码语言:javascript
复制
FS«

在输入字符串上循环。

代码语言:javascript
复制
≔⊟Φ⁵№§ηκιζ

查找包含当前输入字符的条目。

代码语言:javascript
复制
⊞υ⪫[]⁺⁺§⪪“"∧|⌊AuüQ⁷~⊙<⁷≕u?ψμ”,ζ×+[]][²×-~[]⌕§ηζι

将压缩的字符串"[][[]],![],!![],~[]/[],{}"拆分到逗号上,并接受匹配的条目,然后将其与"+[]]["连接起来,并进行适当次数的"-~[]"重复,最后将所有内容封装在最后一组[]中。

代码语言:javascript
复制
»⪫υ+

把一切都和+s联系起来。

票数 2
EN
页面原文内容由Code Golf提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://codegolf.stackexchange.com/questions/198472

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档