11
\$\begingroup\$

This is the robbers' thread. The cops' thread is here.

Your challenge is to take an uncracked submission from the cops' thread and find, for what input or inputs, the program will print Hello, World! and a newline. Capitalization, spacing, and punctuation must be exact.

Please comment on the cop's submission when you've cracked their code.

\$\endgroup\$
0

35 Answers 35

12
\$\begingroup\$

Bash by Sisyphus

Original code:

[[ ! "${1////x}" =~ [[:alnum:]] ]]&&[[ $# = 1 ]]&&bash -c "$1"

Input:

__=; (( __++, __-- ));
(( ___        = __,        ___++));
(( ____       = ___,       ____++));
(( _____      = ____,      _____++));
(( ______     = _____,     ______++));
(( _______    = ______,    _______++));
(( ________   = _______,   ________++));
(( _________  = ________,  _________++));

${!__##-} <<<\$\'\\$___$______$_______\\$___$______$_____\\$___$_______$__\\$___$_______$_________\'\ \$\'\\$___$___$__\\$___$______$_______\\$___$_______$______\\$___$_______$______\\$___$_______$_________,\ \\$___$____$_________\\$___$_______$_________\\$___$________$____\\$___$_______$______\\$___$______$______\\$__$______$___\'

Explanation:

This encodes "echo Hello, World!" as octal escape sequences (\xxx).

Except you also can't use numbers, so the first part builds up variables for the numbers 0-7. You can use those to build a string with octal sequences that will evaluate to give you the actual command.

But eval is also alphanumeric. So instead this pipes that string as input to another instance of bash. $0 contains the name of the command used to invoke Bash, which is usually just bash (or -bash for a login shell) if you're running it normally (through TIO or by pasting it in a terminal). (This incidentally means that if you try to run this by pasting it into a script, things will go horribly wrong as it tries to fork itself a bunch of times.)

But anyway, you can't say $0 directly. Instead, $__ contains the name of $0 ("0"), and you can use indirect expansion to access it (${!__} refers to the contents of $0).

And that, finally, gives you all the pieces you need.

\$\endgroup\$
2
  • \$\begingroup\$ Welcome to Programming Puzzles & Code Golf! I've left a comment on the cop answer. TIO link for the interested: tio.run/##jc/… \$\endgroup\$
    – Dennis
    Aug 7, 2017 at 7:01
  • \$\begingroup\$ Nice! My solution looked different, but used the same idea - constructing an octal string and using the dollar single quote syntax, and using indirection. Well done =) \$\endgroup\$
    – Sisyphus
    Aug 7, 2017 at 7:40
4
\$\begingroup\$

05AB1E, Adnan

•GG∍Mñ¡÷dÖéZ•2ô¹βƵ6B

-107

Try it online!

How?

•GG∍Mñ¡÷dÖéZ•        - big number
             2ô      - split into twos (base-10-digit-wise)
               ¹β    - to base of input
                   B - convert to base (using 012...ABC...abc...):
                 Ƶ6  -   107 (ToBase10(FromBase255(6))+101 = 6+101 = 107)
\$\endgroup\$
1
  • \$\begingroup\$ Negative base...pretty... \$\endgroup\$ Aug 5, 2017 at 20:25
3
\$\begingroup\$

totallyhuman, Python 2

A solution is

'Uryyb, Jbeyq!' 
\$\endgroup\$
1
  • \$\begingroup\$ Explanation? ---- \$\endgroup\$
    – MD XF
    Aug 5, 2017 at 18:08
3
\$\begingroup\$

Pyth: Mr. Xcoder

"abcdefghijklmnopqrstuvwxyz"

G is the built-in for the lowercase alphabet. The code checks for equality against that.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Nice crack :))) \$\endgroup\$
    – Mr. Xcoder
    Aug 5, 2017 at 18:19
3
\$\begingroup\$

Jelly: EriktheOutgolfer

〡㋄ⶐ✐сᑀ⟙ⶐⶐ〡ސЀᶑ〡㋄ⶐ✐сᑀ⟙ⶐⶐ〡ސЀᶑ〡㋄ⶐ✐сᑀ⟙ⶐⶐ〡ސЀᶑ〡㋄ⶐ✐сᑀ⟙ⶐⶐ〡ސЀᶑ〡㋄ⶐ✐сᑀ⟙ⶐⶐ〡ސЀᶑ〡㋄ⶐ✐сᑀ⟙ⶐⶐ〡ސЀᶑ〡㋄ⶐ✐сᑀ⟙ⶐⶐ〡ސЀᶑ〡㋄ⶐ✐сᑀ⟙ⶐⶐ〡ސЀᶑ〡㋄ⶐ✐сᑀ⟙ⶐⶐ〡ސЀᶑ〡㋄ⶐ✐сᑀ⟙ⶐⶐ〡ސЀᶑ〡㋄ⶐ✐сᑀ⟙ⶐⶐ〡ސЀᶑ〡㋄ⶐ✐сᑀ⟙ⶐⶐ〡ސЀᶑ〡㋄ⶐ✐сᑀ⟙ⶐⶐ〡ސЀᶑ

Jelly, 11 bytes

sLƽ$Xṙ5O½Ọ

Try it online!

Explanation

The original code can be explained as such:

sLƽ$Xṙ5O½Ọ  Main link; argument is z
s            Split z into n slices, where n is:
    $
  ƽ         The integer square root of
 L                                      the length of z
     X       Random of a list. Returns a random row of the input put into a square
      ṙ5     Rotate the list left 5 times
        O    Get codepoints
         ½   Floating-point square root
          Ọ  From codepoints

So, just take "Hello, World!" and get codepoints, square them, cast back to codepoints, rotate right 5 times, and then square and flatten the result.

\$\endgroup\$
3
\$\begingroup\$

Octave by Stewie Griffin

Not sure if this is the correct solution (on TIO it prints the \00 character), but in my octave-cli shell it looks like this:

Octave shell

Also in the original challenge it says print nothing (or the null-character), so if nothing is the same as \00 then this should be fine.

[72, 101, 108, 108, 111, 44, 32, 87, 111, 114, 108, 100, 33, 0]

Try it online!

\$\endgroup\$
11
  • \$\begingroup\$ But that's not what the challenge looks like, if so this would me much easier (replace the last 0 with a 10). \$\endgroup\$ Aug 5, 2017 at 20:24
  • \$\begingroup\$ @BruceForte That is what the challenge asks: "Your challenge is to write a program or function that, with a certain input, prints the exact string Hello, World! and a newline." is an exact quote from the challenge. And indeed, that makes the answer trivial. \$\endgroup\$
    – hvd
    Aug 5, 2017 at 20:34
  • \$\begingroup\$ @hvd Yeah, but if you look at the image of the OP his solution does not, that's where the main confusion comes from. \$\endgroup\$ Aug 5, 2017 at 20:37
  • 1
    \$\begingroup\$ @HyperNeutrino FWIW this is what I think the intended style of solution is. \$\endgroup\$ Aug 6, 2017 at 0:54
3
\$\begingroup\$

Python 3 by rexroni

print("Hello, World!") or __import__('sys').exit(0)

Prevent any errors by exiting early.

Try it online!

\$\endgroup\$
3
\$\begingroup\$

JavaScript (ES6) By Ephellon Dantzler

{length:1, charCodeAt:()=>(e='Hello, World!', String.fromCharCode=()=>'')}

Try it online!

That was pretty easy.

I noticed that any string inputs wouldn't be possible to output Hello, World! because the whole thing inside String.fromCharCode will only return multiples of 4, and ! has a char code of 33. So clearly we just have to hack the whole program. Hacking built-ins in JavaScript is trivial if one doesn't try to stop them (and even if one does so, there are usually lots of workarounds...).

\$\endgroup\$
3
\$\begingroup\$

JavaScript (ES6), Voile

Simple proxy that only returns the wanted character every 3rd time it's called.

var i = 0;
var string = "Hello, World!";
var proxy = new Proxy([], {
  get: function(target, property) {
    if (!(++i%3)) {
      return string[property];
    }
    return [1];
  }
});

Try it online!

\$\endgroup\$
1
  • 2
    \$\begingroup\$ Yes, this is the intended solution :) Proxy needs more love. \$\endgroup\$
    – Voile
    Aug 7, 2017 at 12:37
3
\$\begingroup\$

Ruby, by Histocrat

The magic input is: 1767707618171221 30191World!

Try it online.

Explanation:

  • the number 1767707618171221 is a prime, and, written in base 36 it is "hello". When capitalized, this produces "Hello", which is printed using $><<
  • the line $><<", #$'"if/30191/ looks for the number 30191 in the input and writes to stdout a string composed of a comma, a space, and whatever is in the input after the 30191 (using the $POSTMATCH, which is referred here by its short variant, $').
\$\endgroup\$
3
\$\begingroup\$

Lua 5.1 by tehtmi

Pass this as the first argument:

C=("").char;_G[C(112,114,105,110,116)](C(72,101,108,108,111,44,32,87,111,114,108,100,33))

Assuming the original code is in a file tehtmi.lua, run (in bash or a similar shell):

lua tehtmi.lua 'C=("").char;_G[C(112,114,105,110,116)](C(72,101,108,108,111,44,32,87,111,114,108,100,33))'

It also works on Lua 5.3, which is what TIO uses, so why don't you try it online? I haven't tested on a implementation that uses the "PUC-Rio's Lua 5.1" core (because I can't really find any information), but my solution probably also works there.

How?

It runs the first argument as code, but only if it contains less than 5 lowercase characters.

The trick is to run print("Hello, World!"). Another way this can be run is using _G["print"]("Hello, World!"), which only uses strings.

But we can't use the string directly due to the lowercase-count restriction, however, you can run ("").char to get the function string.char, that can convert from a series of bytes to a string. I assigned it to an uppercase variable (so we don't hit the limit) so we can use it to construct both the print and the Hello, World! strings that can be used like above.

\$\endgroup\$
1
  • \$\begingroup\$ Ah, well done! I was thinking of using next instead of char which doesn't work on Lua 5.3 due to randomization of iteration order. \$\endgroup\$
    – tehtmi
    Aug 6, 2017 at 22:15
3
\$\begingroup\$

JavaScript (ES6) by Voile

Input must be a string containing this:

e(
`\
_\
=\
>\
"\
H\
e\
l\
l\
o\
,\
 \
W\
o\
r\
l\
d\
!\
"\
+\
\`
\`
`)

Try it using this:

const e=eval,p=''.split,c=''.slice,v=[].every,f=s=>(t=c.call(s),typeof s=='string'&&t.length<81&&v.call(p.call(t,`\n`),l=>l.length<3)&&e(t)(t))

input='e(\n`\\\n_\\\n=\\\n>\\\n\"\\\nH\\\ne\\\nl\\\nl\\\no\\\n,\\\n \\\nW\\\no\\\nr\\\nl\\\nd\\\n!\\\n\"\\\n+\\\n\\`\n\\`\n`)'
console.log(f(input))

If you don't care about the trailing newline requirement for the output, you can replace the last 6 lines with this instead:

!"
`)

How I did it

The restrictions on the input are that it's a string, each line is two bytes long or less, and that the total length is 80 bytes or less. My first attempt after understanding that correctly was this:

_
=>
`\
H\
e\
l\
l\
o\
,\
 \
W\
o\
r\
l\
d\
!
`

Note: the \s are to ignore the newlines in the string in the input. This is incredibly crucial to the answer, and I can't believe that I stumbled upon it on accident. (I was familiar with it before but forgot about it)

But this didn't work, since the => has to be on the same line as the arguments. Thankfully, I had the idea of wrapping something similar in a string and putting an eval in my input to reduce it to one line, resulting in my final answer. After the eval in the input occurs, the following is generated as a string (which is then eval'd to a function and then run):

_=>"Hello, World!"+`
`

This was really tough to crack, but I succeeded in the end.

Also, first crack ever!

\$\endgroup\$
3
\$\begingroup\$

Cubically by MD XF

I imagine this is always dangerous, but I think I have a crack, pending that I am correct in that there is a bug in the interpreter (which I just now compiled).

My input

0 1 0 1 0 1 0 1 1 0 1 0 0

Output is Hello, World!\n\n\n\n\n\n\n\n\n\n..... with unending newlines.

But I noticed the last section of code:

:1/1+1$(@6)7

sets the notepad to 0x0A (newline) in a scary way, reads input to face 7 (the input face), and then prints the 6 face (notepad face) repeatedly until the 7 face is zero. If you set face 7 to zero, you should only get one newline. However, I got infinite newlines and my 13th input WAS a zero, and I can verify that the 7 face is always zero by inserting a "print number from 7 face" in the loop:

:1/1+1$(@6%7)7

then it prints unending \n0 pairs.

I am looking at the specs on the cubically github page and this behavior looks an awful lot like a bug. Changing the last character of the original program from a 7 to a 0 results in the expected behavior. The TIO interpreter exhibits the same incorrect behavior.

\$\endgroup\$
1
  • \$\begingroup\$ Should be fixed now, as soon as Dennis pulls Cubically it'll be fixed on TIO. \$\endgroup\$
    – MD XF
    Aug 10, 2017 at 16:36
2
\$\begingroup\$

CJam, Erik the Outgolfer

q5/:i:c

00072001010010800108001110004400032000870011100114001080010000033

Try it online!

How?

q       - Take input (string)
 5/     - split into chunks of five
   :i   - cast to integers
     :c - cast to characters
\$\endgroup\$
2
\$\begingroup\$

C# (.NET Core), Grzegorz Puławski

The solution I found makes very substantial use of unprintable characters, so attempting to paste it here didn't work well. The byte values for the input are:

109, 89, 4, 121, 3, 11, 8, 29, 37, 38, 27, 25, 72, 4, 4, 4, 3, 3, 3, 4, 4, 37, 3, 27, 4, 3

Or the string version is available in the input field of the TIO link.

Try it online!

The original program would take the distinct characters in the input, then reverse the input and multiply the elements of the two lists. Thus I created a string 26 characters long where the first 13 characters were distinct, the last 13 characters all also appeared in the first 13, and each pair of indexes [i, 26-i] multiplied to the byte value of the i-th character in Hello, World!.

\$\endgroup\$
1
  • \$\begingroup\$ Great job! You managed to omit the Take(a.First()-33) trap. It also made me realise I forgot Disctinct on the Reverse, but oh well, still made for a nice challenge I think. Also it had %255 so you could use higher numbers, in printable ASCII. \$\endgroup\$ Aug 6, 2017 at 10:36
2
\$\begingroup\$

Ly, LyricLy

n[>n]<[8+o<]

2 25 92 100 106 103 79 24 36 103 100 100 93 64

Try it here (although the page does not render the newline).

n takes input, trys to split on spaces and cast to ints, these get put on the stack. o prints ordinal points, and 8+ does what one would think. So input needs to be 8 less than the codepoints in reverse order split by spaces.

\$\endgroup\$
4
  • \$\begingroup\$ This doesn't print a trailing newline, does it? \$\endgroup\$
    – LyricLy
    Aug 6, 2017 at 1:14
  • \$\begingroup\$ Ah oops, easily rectifiable! \$\endgroup\$ Aug 6, 2017 at 1:16
  • \$\begingroup\$ ...actually is it? I would have thought 2 would work - is that just the herokuapp page not rendering it? \$\endgroup\$ Aug 6, 2017 at 1:19
  • 1
    \$\begingroup\$ Yeah, adding 2 works. The page just doesn't render trailing newlines. \$\endgroup\$
    – LyricLy
    Aug 6, 2017 at 1:19
2
\$\begingroup\$

C (gcc), by Felix Palmen

Original code:

#define O(c)(((char**)v)+c)
#define W(c)*(O(c)-**O(2)+x)
main(x,v){puts(W(42));}

Arguments:

"Hello, World!" ","

Try it online!

Explanation:

W(c) is calculating the address of a string from the argument list to print out. It starts with the address of the cth argument (O(c)), which is the 42nd argument in this case, and then subtracts the first character of the second argument (**O(2)) as an integer offset, and then adds x, which is the number of arguments.

W(c) uses the second argument, so you know there need to be at least 3 of them (0, 1, 2). Then "Hello, World!" can go in the first argument, and then to address that argument you need a character whose ASCII value fits in the equation "42-x+3=1". That happens to be ",".

\$\endgroup\$
1
  • \$\begingroup\$ Great explanation, I'll edit my post as soon as I'm on a PC :) \$\endgroup\$ Aug 8, 2017 at 6:01
2
\$\begingroup\$

JavaScript: ThePirateBay

I override the valueOf() and toString() methods of the parsed objects so that coercion fails with a TypeError.

{"valueOf": 7, "toString": 7}
\$\endgroup\$
4
  • 12
    \$\begingroup\$ Umm, I can't seem to understand. Please elaborate or something? Especially the dalksdjalkdjaS djalksdjalksdja part, it somewhat confuses me. \$\endgroup\$ Aug 5, 2017 at 19:09
  • \$\begingroup\$ @EriktheOutgolfer I edited out the spam part, but I have no idea why it was there. \$\endgroup\$ Aug 8, 2017 at 16:40
  • \$\begingroup\$ @EriktheOutgolfer oh lol. That was passing to stop my answer from auto-converting to a comment. \$\endgroup\$
    – Maltysen
    Aug 12, 2017 at 5:23
  • 1
    \$\begingroup\$ @Maltysen Well there's an edit button right there which can be useful next time ;) \$\endgroup\$ Aug 12, 2017 at 11:29
2
\$\begingroup\$

6502 Assembly (C64) - Felix Palmen

The correct answer is ,52768,23

The explanation is slightly involved.

00 c0                          ;load address
20 fd ae      jsr $aefd        ; checks for comma
20 eb b7      jsr $b7eb        ; reads arguments

The code first checks for a comma (syntax necessity) and then reads in two arguments, the first of which is a WORD, stored little-endian in memory location 0014 and 0015, the latter of which is stored in the X register.

8a              TXA            ;Store second argument into A (default register)
0a              ASL            ; bitshifts the second argument left (doubles it)
45 14           EOR $14        ; XOR that with the low byte of first argument
8d 21 c0        STA $c021      ; Drop that later in the program

That's pretty clever, using our input to rewrite the program. It eventually rewrites the counter for the output loop at the end of the program.

45 15           EOR $15        ; XOR that with the high byte of the first argument
85 15           STA $15        ; Put the result in $15
49 e5           EOR #$e5       ; XOR that with the number $e5
85 14           STA $14        ; Put that in $14

Here comes the devious part:

8e 18 d0        STX $d018      ; stores the original second argument in d018

on the C64, d018 is a very important byte. It stores the reference points for things involving the screen's output. See here for more info. If this gets a wrong value, it will crash your C64. In order to print the requisite mixed upper and lowercase letters, this needs to be $17.

Now we begin our output loop:

a0 00               ldy #$00       ; zeroes out the Y register
b1 14               lda ($14),y    ; puts the memory referenced by the byte
                                   ;   starting at $14 (remember that byte?)
                                   ;   into the default register
20 d2 ff            jsr $ffd2      ; calls the kernal routine to print the char stored in A
c8                  iny            ; increment Y
c0 0e               cpy #$0e       ; test for equality with the constant $0e

That constant is what got written over before. It clearly determines how long the loop runs. It happens to be the right value already, but we need to stick 0e there again.

d0 f6                   bne *-8        ; jump back 8 bytes if y and that constant weren't equal
60                      rts            ; ends the program

The rest is just the information which we need to print out, starting at memory address c025.

So it's just following the math from there.

\$\endgroup\$
3
  • \$\begingroup\$ Absolutely correct, congrats. Might take me a while to properly edit my post, I'm on mobile now. \$\endgroup\$ Aug 10, 2017 at 16:08
  • \$\begingroup\$ The d018 was very clever, and i like how you posted a hint secretly. \$\endgroup\$
    – A Gold Man
    Aug 10, 2017 at 16:09
  • \$\begingroup\$ d018 was the intended door-opener ... the hint was accidental, i meant $FF there, but then decided to leave it. \$\endgroup\$ Aug 10, 2017 at 16:12
2
\$\begingroup\$

6502 Machine Code (C64) - Felix Palmen

The correct answer is

8bitsareenough

The code is rather complicated, involving a lot of self modifying. So instead of fully reverse engineering it, you can just use it to crack itself.

Here's a slightly more helpful disassembly of the code, to help understand what happened. The syntax is for KickAssembler.

*=$c000       // LOAD ADDRESS
jsr $aefd     //checks for a comma
jsr $ad9e     /*Reads in an argument. Stores length of it into
                $61, with the address of the stored arg in $62-3*/
jsr $b6a3     /*Evaluates the string, leaving the pointer on $22-3
                and the length on A*/ //I think

ldy #$00
loop: lda thedata,y   
cpy #$01
beq shuffle
cpy #$07
beq shuffle
cpy #$0b
beq shuffle
tricks: jsr output
iny
bne loop
output: eor ($22),y      //XOR's A with the y-eth letter of our input
jmp $ffd2               //good old CHROUT, returns to tricks above
thedata: .byte $f0,$48,$fa,$a2, $1c,$6d,$72,$30
.byte $06,$a9,$03,$48,$7c,$a3
shuffle: sta $c048      //drops A in mystery+4, over the constant
lda $c026,y
sta $c045               //overwrites the low byte of mystery
lda $c027,y
sta $c046               //overwrites the high byte of mystery
ldx #$00
mystery: lda $aefd,x              
eor #$23
jsr output
iny
inx
cpx #$03
bne mystery
cpy #$0e
bne loop
eor #$1a
sta $d018                
rts

Labelling it up like this was enough for me to see that the code XORs a bunch of constants that are hidden around in order to print out what we need. Since XOR is reversible, if you input the desired output, it'll tell you what the key is.

So I switched the last line

/*from sta $d018 
to*/ jsr $ffd2

so it would print the last required input instead of crashing on a wrong input.

And that's that!

If there's any interest, I'll crack the code more.

\$\endgroup\$
4
  • \$\begingroup\$ Wow, this is in fact a huge shortcut, I probably should have forced a crash on wrong input earlier in processing. There was another shortcut possible btw, using the debugger of vice. But whatever, it's the correct solution. \$\endgroup\$ Aug 15, 2017 at 7:18
  • \$\begingroup\$ I didn't know that vice has a debugger. This is what I get for learning a language just to crack answers. \$\endgroup\$
    – A Gold Man
    Aug 15, 2017 at 7:20
  • \$\begingroup\$ Edited my post, with some explanations. Good job, just modifying the program not to crash of course is a quite obvious way, I didn't think of this. \$\endgroup\$ Aug 15, 2017 at 7:31
  • \$\begingroup\$ Nitpick: "drops A in mystery+1, over the constant" <- that's actually mystery+4 with your label. Offests are in bytes :) and FWIW, self-modification is quite common even in serious 6502 code, as long as the code runs from RAM. \$\endgroup\$ Aug 15, 2017 at 9:14
1
\$\begingroup\$

Explode, Step Hen

@_?&4_-j>5&f^~c>&6\|4>7

Rh/qi?,Wcr+du

Try it online!

  • Trying to work out what all the "explorers" are actually doing hurts one's head too much, so I just reverse engineered it (literally :p - starting from the rightmost character I offset each in turn along [and around] the printable character range).
\$\endgroup\$
1
  • \$\begingroup\$ Good job :) I'll add an explanation in a couple hours when I'm back at my PC \$\endgroup\$
    – Stephen
    Aug 6, 2017 at 12:42
1
\$\begingroup\$

C (tcc) by Joshua

int puts(const char *s)
{
    printf("Hello, World!%s", s);
}

Try it online!

\$\endgroup\$
4
  • \$\begingroup\$ Darn. I had this exact crack but couldn't get it working on TIO. +1 \$\endgroup\$
    – MD XF
    Aug 6, 2017 at 4:43
  • \$\begingroup\$ Sorry 'bout that. Fwiw it's fixed now. \$\endgroup\$
    – Dennis
    Aug 6, 2017 at 4:50
  • \$\begingroup\$ Do you know what the problem was? \$\endgroup\$
    – MD XF
    Aug 6, 2017 at 20:31
  • \$\begingroup\$ I know how I fixed it (tcc had to be built with SELinux support), but I'm not sure what that does or why it was needed in the first place. \$\endgroup\$
    – Dennis
    Aug 6, 2017 at 23:32
1
\$\begingroup\$

MATL by Luis Mendo

tsZp?x

Try it online!

\$\endgroup\$
1
\$\begingroup\$

Jelly by Jonathan Allan

Original code:

œ?“¥ĊɲṢŻ;^»œ?@€⁸ḊFmṪ⁷

Try it online!

Input:

1,2586391,2949273,3312154,3312154,1134001,362881,2223505,766081,1134001,1497601,3312154,1860601,140

Explanation:

Mainly, it is necessary to understand what the code does. The first thing it does is it takes the string "!,Word Hel" (with all the needed characters except newline) and creates a bunch of permutations of them. The inputs specify permutation numbers, and each pair of permutations from the input is applied to the string exluding pairs where the first permutation is applied first. Basically, P2(P1(S)), P2(P2(S), P2(P3(S)), ..., P2(PN(S)), P3(P1(S)), ..., P3(PN(S)), ... ..., PN(P1(S)), ..., PN(PN(S)). These are all concatenated together. Then the last input is reused to take every PNth character from this big string. So, I take PN = len(S)*N = 10*N. This means we'll take the first character of P2(P1(S)), the first character of P3(P1(S)), all the way up to the first character of PN(P1(S)). To simplify further, I let P1 = 1 which is the identity permutation. Then it suffices to choose any P2 that permutes "H" into the first position, a P3 that permutes "e" into the first position and so on. Luckily, small permutation numbers like the one already chosen for PN don't affect the earlier characters in the string, so PN leaves "!" at the beginning of the string. (If this wasn't true, it would still be possible to solve by choosing a different P1.)

\$\endgroup\$
1
  • \$\begingroup\$ It takes 14 permutations of the list of the 14 permutations, flattens, dequeues and then takes every 140th character. \$\endgroup\$ Aug 6, 2017 at 13:12
1
\$\begingroup\$

C (GCC on TIO) by MD XF

4195875

Try it online!

How?

It tries to print the second argument as a string, which is a pointer we can determine on the input. It just so happens that at location memory 4195875 starts the "Hello, World!\n" string.

The number was determined by adding print("%p", "Hello, World!"); before the printf, converting the hexadecimal number to decimal and tried it out on the original TIO. However, it showed me the printf format string. By trying out some numbers, I found out that the string is located before the format string.

So in memory, it would look like this (as a C string):

Hello, World!\n\0%2$s\0

This also means that any update to the compiler might break the solution.

\$\endgroup\$
1
\$\begingroup\$

JavaScript (Node.js) By Voile

['Hello, World!','','','','','','','','','','','','']

Try it online!

\$\endgroup\$
1
\$\begingroup\$

Röda by fergusq

[1, "HH", 1, "eellloo", 1, ",,", 1, "  WWoo", 1, "rr", 1, "ll", 1, "dd", 1, "!!"]

Try it online!

Explanation coming in a bit...

\$\endgroup\$
1
\$\begingroup\$

JavaScript (ES6), Voile

var i = 0;
var string = `"${t}"`;
var answer = "i++?0:q=string";
console.log( f(answer) );

Try it online!

\$\endgroup\$
1
  • \$\begingroup\$ That's not the intended solution :) I'll fix it and be back later. \$\endgroup\$
    – Voile
    Aug 7, 2017 at 11:44
1
\$\begingroup\$

PHP by LP154

PDO,FETCH_CLASSTYPE

Try it online!

(TIO doesn't have the PDO class defined, so the above demo uses a codepad that does)

Another solution:

ReflectionFunction,IS_DEPRECATED

Try it online!

\$\endgroup\$
1
\$\begingroup\$

JavaScript (ES6), Voile

Given the 81 character limit, this probably isn't the intended solution

global.g = ()=>"Hello, World!";
var str = "g";

Try it online!

\$\endgroup\$
11
  • \$\begingroup\$ Genious. passing one char string with global manipulation. Seems, that it is intended solution \$\endgroup\$ Aug 7, 2017 at 16:13
  • \$\begingroup\$ That's not the intended solution :( \$\endgroup\$
    – Voile
    Aug 7, 2017 at 16:18
  • \$\begingroup\$ Now that I'm thinking about it, I don't think it's allowed to do tons of stuff like this before passing input in a function, unless said stuff can also be composed as part of the input (e.g inside the function which will be evaluated inside), since the challenge requires you to make a input that will result in 'Hello, World!', not a full program. Otherwise pretty much nothing can be safe. So I think this crack might be invalid? \$\endgroup\$
    – Voile
    Aug 7, 2017 at 16:31
  • \$\begingroup\$ @Voile It very well may be. I think it's fair to read the task as if the input must stand alone (i.e. without changes to the external system) - especially if this isn't the intended solution :) No need to mark your cop as cracked. \$\endgroup\$
    – Birjolaxew
    Aug 7, 2017 at 16:39
  • 1
    \$\begingroup\$ I've made a meta post discussing about this. Feel free to leave some discussions there. \$\endgroup\$
    – Voile
    Aug 7, 2017 at 18:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.