A Ken Thompson virus is a virus that infects your compiler and other programs. Since it infects all your tools, you can not detect it without using tools from before the virus was introduced.
Your will create a prototype for inserting the Ken Thompson virus into code. The goal of this virus will be to allow you to (fake) destroy any computer running a program infected with it.
Inserting a Ken Thompson virus is defined as follows. Start with an input program P
. Your program will output a modified program Q
that works as follows:
- If the input to
Q
isaNouIQ5xKvUfdZVzo0Xs
, it will outputBOOM
(in a real Ken Thompson virus, this would actually do something bad, but since it this is a fake virus, outputingBOOM
is done instead). - For any other input to
Q
, run programP
with that input- If the output of
P
is valid source code in the language you are using, insert the Ken Thompson virus into it and thenQ
will output the resulting infected program. - Otherwise, the output of
Q
is just the output ofP
.
- If the output of
You will write a program that takes P
's code as input and produces Q
's code as output.
You can use either a currently (at the time of this post) existing programming language, or a subset of one, for this challenge. (The idea is that language you are using would be the target language of some self-compiling compiler, but this is not required.) Since you want to be as subtle as possible, the shortest code (in bytes) wins!
Insert a simulated Ken Thompson virus into a program
,The goal of this virus will be to allow you to (fake) destroy any computer
. All the "virus" does is printBOOM
. There is absolutely nothing malicious. \$\endgroup\$