38
1
This is part of a cops-and-robbers challenge. Go here for the robbers' part.
The Cops' Challenge
You should write a program or function in a language of your choice, which outputs the string Haystack
. However, it must be possible to remove some subset of characters from your program (without reordering the rest), such that the resulting string is also a valid program in the same language, which prints Needle
instead. Both programs/functions may optionally print a single trailing newline (independently of each other), but nothing else. Output is case sensitive and must follow the exact casing provided.
Your goal, of course, is to hide the "needle" very well. But note that your submission can be cracked with any valid solution, not just the one you intended.
Please include in your answer:
- The language (and version if relevant) of your submission.
- The size of the Haystack program in bytes.
- The Haystack program itself.
- The output method if it's not STDOUT.
- If possible, a link to an online interpreter/compiler for your chosen language.
Your submission may be either a program or function, but not a snippet and you must not assume a REPL environment. You must not take any input, and you may output via STDOUT, function return value or function (out) parameter.
Both programs/functions have to complete within 5 seconds on a reasonable desktop machine and need to be deterministic. You must not use built-ins for hashing, encryption or random number generation (even if you seed the random number generator to a fixed value).
In the interest of fairness, there must be a freely available interpreter or compiler for your chosen language.
An answer is cracked if the Needle program is found. If your answer has not been cracked for 7 days, you may reveal the intended Needle program in your answer, which renders your submission safe. As long as you don't reveal your solution, it may still be cracked by robbers, even if the 7 days have already passed. The shortest safe Haystack program (measured in bytes) wins.
Examples
Here are a couple of simple examples in different languages:
Ruby
Haystack: puts 1>0?"Haystack":"Needle"
Delete: XXXXXXXXXXXXXXX
Needle: puts "Needle"
Python 2
Haystack: print "kcatsyaHeldeeN"[-7::-1]
Delete: XXXXXXXX XX
Needle: print "eldeeN"[::-1]
Note that the subset of removed characters doesn't have to be contiguous.
Uncracked Submissions
<script>site = 'meta.codegolf'; postID = 5686; isAnswer = false; QUESTION_ID = 144600;</script><script src='https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js'></script><script>jQuery(function(){var u='https://api.stackexchange.com/2.2/';if(isAnswer)u+='answers/'+postID+'?order=asc&sort=creation&site='+site+'&filter=!GeEyUcJFJeRCD';else u+='questions/'+postID+'?order=asc&sort=creation&site='+site+'&filter=!GeEyUcJFJO6t)';jQuery.get(u,function(b){function d(s){return jQuery('<textarea>').html(s).text()};function r(l){return new RegExp('<pre class="snippet-code-'+l+'\\b[^>]*><code>([\\s\\S]*?)</code></pre>')};b=b.items[0].body;var j=r('js').exec(b),c=r('css').exec(b),h=r('html').exec(b);if(c!==null)jQuery('head').append(jQuery('<style>').text(d(c[1])));if (h!==null)jQuery('body').append(d(h[1]));if(j!==null)jQuery('body').append(jQuery('<script>').text(d(j[1])))})})</script>
1Related. (The main difference is that that one had the programs implement OEIS sequences and allowed the cracked program to output any different OEIS sequence, which makes it a lot harder for the cops to guard against unintentional cracks. It also allowed robbers to steal cracks from other robbers by finding even shorter solutions.) – Martin Ender – 2017-10-07T14:21:11.503
I would do this in Haystack but it has no documentation and I cbb looking through the code :( – Okx – 2017-10-07T15:45:21.280
@Okx https://github.com/kade-robertson/haystack/wiki/Documentation
– HyperNeutrino – 2017-10-07T15:50:33.367To brute-force a n - byte submission, you have to check 2^n - 1 sub-programs. Each is required to complete within 5 seconds. If you check programs consecutively, you need about 7.5 days for a 17-byte submission. So this is the lower bound for an expected safe submission :-) – M.Herzkamp – 2017-10-09T15:30:33.050
1
The stack snippet gets the length wrong for this answer
– mbomb007 – 2017-10-09T20:02:23.923@M.Herzkamp I don't think every possible subprogram must complete within 5 seconds, just the Haystack and Needle ones? – kamoroso94 – 2017-10-14T11:23:24.450
1@kamoroso94 Yes, but that means you can terminate candidate programs after 5 or 6 seconds, because if they haven't finished they can't be the solution you're looking for. – Martin Ender – 2017-10-14T11:24:50.610
What are treated as hashing, encryption or random number generation – l4m2 – 2017-12-15T18:56:57.317
You should accept this safe TI-Basic Answer at 119 bytes
– FantaC – 2018-01-17T00:06:13.603