Python 3, 70 bytes, cracked by @ovs
c=compile(c:=open(0,"rb").read(),"","exec").replace(co_code=c)
exec(c)
Works in CPython 3.9.6. Takes input from STDIN and should output 42
with a trailing newline to STDOUT.
@ovs has crackedThe challenge was to create something of a polyglot between Python source code and CPython bytecode. The Python source would be compiled (so it needed to be syntactically valid), and then have its bytecode replaced with a nice solutionitself, but before I reveal mine I'd likekeeping constants and names.
My solution was:
d,F,d,S,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,44,43,42
Disassembly:
Bytes Instruction Argument Meaning
d, LOAD_CONST 44 stored integer 42
F, PRINT_EXPR 44 ignored
d, LOAD_CONST 44 stored integer 42
S, RETURN_VALUE 44 ignored
... [garbage...]
The list of numbers is just to see if anyone can do it withoutget the Python compiler to store enough constants for #,
(byte 0x23decimal codepoint 44)? to be a valid argument in order to index into the tuple and load 42
.
By the way, PRINT_EXPR
is an opcode used solely by the Python shell to print the return value of an expression. It's never used in normal code, but it's very useful for hacking around in bytecode-land.