javascript的一个常见的模因方面是它极其松散的类型强制,它允许+!![]+[+[]] == '10',这种技术也可以用于创建字母,如下面的示例所示:
[[][[]]+[]][+[]][-~[]] == 'n'
[undefined+[]][+[]][-~[]] // [][[]] -> undefined
['undefined'][+[]][-~[]] // undefined+[] -> 'undefined'
['undefined'][0][-~[]] // +[] -> 0
'undefined'[-~[]] // ['undefined'][0] -> 'undefined'
'undefined'[1] // -~[] -> -(-1) -> 1
'n'js矫顽力的一些例子:
[][[]] = 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'注意:表格中的蓝色阴影单元格是字符串,而黄色单元格是文字。
给定一个只有字母abcdefijlnorstuy的字符串,将其转换为只包含计算为原始字符串的字符[]+-~/{}!的有效javascript。请注意,这不是JSFuck,而是完全集中在可以(相对地)简洁翻译的字符串子集上。
可以用字母abcdefijlnorstuy (可以包括空格)写的任何小写字符串
有效的javascript只包含将在js环境中计算为原始单词的字符[]+-~/{}!。
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中进行计算。
不要滥用任何常见的漏洞。
发布于 2020-01-25 04:55:17
这不是一个特别短的解决方案,但使这个挑战有趣,因为它能够使用回溯自动选择哪个字符串和索引到该字符串中使用的每个字符。
`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).% 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).发布于 2020-01-25 11:40:04
≔⪪“<≦ω≕ε…(Bς´B⌈YWγ№Φξ⌕IY¦l ”,ηFS«≔⊟Φ⁵№§ηκιζ⊞υ⪫[]⁺⁺§⪪“"∧|⌊AuüQ⁷~⊙<⁷≕u?ψμ”,ζ×+[]][²×-~[]⌕§ηζι»⪫υ+在网上试试!链接是详细的代码版本。解释:
≔⪪“<≦ω≕ε…(Bς´B⌈YWγ№Φξ⌕IY¦l ”,η在逗号上拆分压缩字符串"\n\nd,\nals,\nru,\\nnfi\n\n\ny,\nobject "。这是数组["undefined", "false", "true", "Infinity", "[object Object]"],只保留空格和唯一的字母,并在最后一个剩余字母处截断以提高压缩效果。
FS«在输入字符串上循环。
≔⊟Φ⁵№§ηκιζ查找包含当前输入字符的条目。
⊞υ⪫[]⁺⁺§⪪“"∧|⌊AuüQ⁷~⊙<⁷≕u?ψμ”,ζ×+[]][²×-~[]⌕§ηζι将压缩的字符串"[][[]],![],!![],~[]/[],{}"拆分到逗号上,并接受匹配的条目,然后将其与"+[]]["连接起来,并进行适当次数的"-~[]"重复,最后将所有内容封装在最后一组[]中。
»⪫υ+把一切都和+s联系起来。
https://codegolf.stackexchange.com/questions/198472
复制相似问题