babypolyquine & polyquine

  • Write-up Author : bruce30262

Description of babypolyquine

Different people see different me.
But I am always myself.

202.112.26.114:12321
Make the output of your program exactly the same as your source code.
At least 3 correct to get this flag

Description of polyquine

Different people see different me.
But I am always myself.

202.112.26.114:12321
Make the output of your program exactly the same as your source code.
All 5 correct required to get this flag
poly_quine.c

Solution

For baby poly quine, I just google the solution and find the following code:
http://shinh.skr.jp/obf/poly_quine.txt

It pass the C, Python2, Ruby & Perl's check. For Python3, it happened to have some syntax error. After changing def printf(a,*b):p a%b to def printf(a,*b):p (a%b), Python3 can run the script now, but it print an extra newline, which isn't match the challenge's requirement. So now we're focusing how to make both python2 & python3 have the same printing behavior. After doing some trial & error, I found that for C, Ruby & Perl, they will ignore the line def printf(a,*b):p (a%b), except Python. So we can add some code at that line. As for my opinion, I add the following code:

from sys import* ; p = lambda x:stdout.write(x)
def printf(a,*b):p (a%b)

For Python, it will import the sys module, and set a lambda p as a stdout.write() function. The stdout.write() function won't print newline, so python2 & python3 will act like the same. For the whole code, see poly_final.

 #include/*
s='''*/<stdio.h>
main(){char*_;/*==;sub _:lvalue{$_}<<s;#';<<s#'''
from sys import* ; p = lambda x:stdout.write(x)
def printf(a,*b):p (a%b)
s
#*/
_=" #include/*%cs='''*/<stdio.h>%cmain(){char*_;/*==;sub _:lvalue{%c_}<<s;#';<<s#'''%cfrom sys import* ; p = lambda x:stdout.write(x)%cdef printf(a,*b):p (a%%b)%cs%c#*/%c_=%c%s%c;printf(_,10,10,36,10,10,10,10,10,34,_,34,10,10,10,10);%c#/*%cs='''*/%c}//'''#==%c";printf(_,10,10,36,10,10,10,10,10,34,_,34,10,10,10,10);
#/*
s='''*/
}//'''#==

poly_final:
https://drive.google.com/file/d/0B2bWJ2sAPCV3ZmtFOVplNXdLUlE/view?usp=sharing