Javascript, score 5
6: x=>21%15
7: x=>22%15
8: x=>23%15
9: x=>24%15
0: x=>1%1
12345QWERTASDFG<>ZXCqwertasdfgzxc!@#$%
Step 1: Functions or programs.
We need to have functions, so we have to take =
, from which we can make x=>[code]
or similar.
So, what can we do with what we've got?
67890 can be made with numeric operations. But for the rest, we need string coercion, which we can't get without some other character.
What if I didn't need functions? (Note - below this is all hypothetical).
We still need some form of string coercion:
- String.fromCharCode
+[]
or +''
- Literally calling toString
The first requires in.omh
, so is obviously not an option.
The second requires +
and either '
,"
, a backtick or []
- Sorry, but no.
The third has the same problems as the first.
So that's all we can do, and it's not enough.
But what about 2 characters?
Sadly, +'
and +"
have no way of getting specific characters. +` adds function calling to our repetoire, but charAt needs an h and a . .
If we start with a string(using backticks because function calling), we can get one character of our choice! But we can't get anything else, so that's a dead end.
Enter escape sequences!
With '
and \
, we can do things like "\153"
or "\x2c"
, netting us a bunch of extra characters! The complete list is:
-: '\55'
i: '\151'
[: '\133'
]: '\135'
j: '\152'
k: '\153'
l: '\154'
b: '\142'
m: '\155'
*: '\52'
): '\51'
+: '\53'
": '\42'
=: '\x3d'
]: '\x5d'
^: '\x5e'
_: '\x5f'
:: '\x3a'
Along with the standard:
': '\''
\: '\\'
This leaves yuoph;n&(|
to deal with.
Checking which character will be the most effective out of 67890b, we get 7, adding 5 characters to our list
y: '\171'
u: '\x75'
o: '\157'
;: '\73'
|: '\174'
And now we're down to phn&(
. Checking again, we find 0 gives us ph(
:
p: '\x70'
h: '\150'
(: '\50'
Leaving us n&
. Finally, 6 unlocks the last two:
n: '\156'
&: '\46'
So our extra charset is '\670
. Note that here we have assembled the full octal set: 01234567
, and can make any character with what we've defined. But what else can we do?
What if we try something different?
What if we use +[]
to start with? +[]
is the basis of most of javascript, and we can now use some previously useless characters. We still have no function calling, but:
We can get .
by taking the second character of 11e111 which is coerced into 1.1e112: [11e111+[]][+[]][1]
From there, we can get -
, by making .0000001 as a string, coercing into a float, which is 1e-7, then coerce back to a string and get the right character : [+[[11e111+[]][+[]][1]+1%1+1%1+1%1+1%1+1%1+1%1+1][+[]]+[]][+[]][2]
We can get the string "undefined" from taking the first of an empty array: [][+[]]+[]
, "true" and "false" from !![]+[]
and ![]+[]
, "NaN" from coercing undefined to a number: +[][+[]]
, and "[object Object]" from CSS+[]
. Adding this, our character pool (as strings only) is now:
"-.undefitrualsNa[objcO]"
We can take []['f'+'i'+'n'+'d']+[]
to get the code of the find function as a string:
function find() {
[native code]
}
Our string character pool is now -.undefitrualsNa[objcO] (){vc}
and newline.
Note that from this we can get "constructor". We can use this like so: []["constructor"]+[]
returns function Array() { \n[native code]\n}
, adding A and y to our pool. [[]+[]][+[]]["constructor"]+[]
returns the string function, giving us S and g. []["find"]["constructor"]+[]
adds F from Function.
So, our current string is -.undefitrualsNa[objcO] (){vc}AySgF
, from which we can take snippets for -yuio[]jlvbn()
by taking arbitrary characters, leaving us with =phk\m^&*_+:"|
to deal with. Note that while +
is in our codebase, it cannot be coerced into a string with only what we have.
Now what?
For the remaining characters, one option is to add ()
, reducing it to JSFuck.
Another option is to add backtick and =
, reducing it to Turing complete javascript
With the new Pipeline operator, all you need is |
(we already have >
), but does this count as valid?
We can also try the afromentioned escape sequences.
In conclusion, restricted-source in Javascript is very difficult.
=>
,alert
,prompt
,console.log
andfunction
are all forbidden and as far as I know there is no other way to output (evenprint
is forbidden) \$\endgroup\$Ctrl
,esc
andalt
allowed keys? \$\endgroup\$,./?`{}~
in either set? \$\endgroup\$