Hide the Needle in the Haystack (Cops)

This is part of a 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.

• 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

• Related. (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 Oct 7 '17 at 14:21
• I would do this in Haystack but it has no documentation and I cbb looking through the code :( – Okx Oct 7 '17 at 15:45
• – hyper-neutrino Oct 7 '17 at 15:50
• The stack snippet gets the length wrong for this answer – mbomb007 Oct 9 '17 at 20:02
• @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 Oct 14 '17 at 11:24

Haystack, 84 bytes, Cracked

0\\1-c\
//
?10F17+c8F+4+cd8F+3+c6-c1+c,c2+c8+c|
0   \1++c,c|
F/c++2F8
c\8F+2+cd

Try it online!

This looks (to me) rather convoluted but if you find the right subset it's a bit too easy... oh well, just to get us started :P

• – fireflame241 Oct 7 '17 at 16:27
• @icrieverytim 1. oo cool they're both unicode glyphs 2. the current one is more scientifically accurate – hyper-neutrino Oct 8 '17 at 14:23
• 1. Yeah, I know, they look really cool. :P I found them in this gold mine of a Unicode block. Don't be surprised if they end up in Neon's code page. 2. TBH, the old one looked better IMO. :P – totallyhuman Oct 8 '17 at 14:31
• @HyperNeutrino Why do you have an interest in benzene? – Michthan Oct 9 '17 at 13:23
• @Michthan Considering that I'm a neutrino, that is a good question, but I don't know :P – hyper-neutrino Oct 9 '17 at 13:28

Hexagony, 37 bytes

H[@;(...e<l.a;./$.>;\sN;\ac.>).;;;._y Try it online! Just my obligatory Hexagony entry... For convenience, here is the unfolded code: H [ @ ; ( . . . e < l . a ; . /$ . > ; \ s
N ; \ a c .
> ) . ; ;
; . _ y

How this works:

The program starts off with H, then we move to IP #5. This IP starts in the west corner, bouncing and wrapping around while executing (in effect) ;a;y;s; (so we've printed Hays). Then s gets incremented to a t by ) and printed, then we pass through Ne...(c before getting to a;c; (still bouncing around a small section of the hexagon). The program hits the _, reflects up through \ to l which gets decremented to a k by (, which passes through another \ before being printed and the program terminates on the @.

Verbose version

H   H is entered into the current memory cell
[   We move to the previous instruction pointer (starting at the / and moving NE)
/   No-op
<   Mirrors the IP back to south-west
/   No-op (IP now wraps to the NE corner)
;   Outputs H
.   No-op
a   a is entered into the current memory cell
>   Mirrors the IP back to north-east
a   a is entered into the current memory cell
.   No-op
;   Outputs a (IP now wraps SE corner)
y   y is entered into the current memory cell
;   Outputs y
.   No-op
s   s is entered into the current memory cell (IP now wraps SW corner)
;   Outputs s
)   Increments the memory cell to t
\   Mirrors the IP west
;   Outputs t
N   N is entered into the current memory cell (IP now wraps to e)
e   e is entered into the current memory cell
... No-ops
(   Decrements the memory cell to d (IP now wraps to . on SE edge)
.   No-op
c   c is entered into the current memory cell
a   a is entered into the current memory cell
\   Mirrors the IP north-east
>   Redirects the IP east
;   Outputs a
\   Mirrors the IP south-west
c   c is entered into the current memory cell
;   Outputs c
_   Mirrors the IP north-west
.\. No-ops
l   l is entered into the current memory cell
(   Decrements the memory cell to k (IP now wraps to . on SE edge)
.\  No-ops
;   Outputs k
.   No-op
@   Terminates the program

• This language still cracks me up. I love you for it. – phroureo Oct 9 '17 at 16:44
• My brain is exploding right now. I was trying to figure this out enough to crack the code, but YEESH man. What kind of twisted guy makes this up?? – phroureo Oct 13 '17 at 18:10
• @phroureo ... >_> – Martin Ender Oct 13 '17 at 18:20
• After your answer is safe, can you give me a step-by-step on what it's doing? (Or if you already have a step-by-step somewhere one something similar, point me there?) – phroureo Oct 13 '17 at 18:22
• @phroureo I don't mind adding an explanation of the cop program before it's safe, and I don't think I'll claim it safe anyway (I'm not too keen on winning my own challenge with a submission that I put barely any effort in). I'll try to add the explanation tomorrow. In the meantime, I'm happy to help you with Hexagony in the esolangs chatroom. – Martin Ender Oct 13 '17 at 19:44

Brain-Flak, 146 bytes (Cracked)

([((((()()())){}){}){}](()([()](()({}([((((()()()){})))[]])[]({}({})[{}]()({}((()(({}){}){}){}){}())))[][][][][][]))[]))(((()[]){}){({}[()()])}{})

Try it online!

Intended solution, 80 bytes

([((((()()())){}){}){}](()([()](()({}([((((()()()){})))[]])[]({}({})[{}]()({}((()(({}){}){}){}){}())))[][][][][][]))[]))(((()[]){}){({}[()()])}{})
( ((   )(                  [(  (( (         )()()){})) []]   ({}(  )    ( (  ( ()(({}){}){}){}){}())))            ))    (((()[]){}){({}[()  ])}{})

JavaScript, 95 bytes (ES6), Cracked

A function returning a string.

f=(k=b=x=35)=>x--?f(k*74837258394056219&268435455):k&2?'N'+(k^124038877).toString(b):'Haystack'

"Haystack" demo

f=(k=b=x=35)=>x--?f(k*74837258394056219&268435455):k&2?'N'+(k^124038877).toString(b):'Haystack'

console.log(f())

• Very nice puzzle. Cracked – ShreevatsaR Oct 7 '17 at 19:15

Haskell, 168 bytes (Cracked by nimi)

hay.(hays.(stackany hay$or id).stack hay <*>hays(sum$stack haystack<$>hay))-}$words
"Haystack Hayst ackH aysta ckH aystac k"

Try it online! Evaluating the identifier h returns the string "Haystack", after some deletions h yields "Needle".

• Cracked. Was quite some fun to solve. – nimi Oct 13 '17 at 13:08

Jelly, 41 bytes (Cracked)

“¿ọ⁽ṅ*FỊ⁼g£¡#!ʋzoɦṪ£ṢÞḲÐɠ`”m3⁾“»jVḟ“¡!pṄ»

Try it online!

Happy hunting!

• – jacobly Oct 8 '17 at 14:09

Hexagony, 32 bytes. Cracked

I couldn't solve Martin's, so I'm posting my own.

];N.@cl;e@;;(\H/;ya;_.>s.;t//<._

Try it online!

Here it is formatted:

] ; N .
@ c l ; e
@ ; ; ( \ H
/ ; y a ; _ .
> s . ; t /
/ < . _ .
. . . .

My aim with this was for both solutions to use as many IPs as possible, I got 6 for Needle and only 5 for Haystack.

Pyth, 44 bytes (Cracked)

Kr."Dn2û"2sf!/+rrK2 2r."EL8"2Tr."AhÐP­®Z"2

Try it here.

• Should be easy to crack, just a first attempt :-) – Mr. Xcoder Oct 7 '17 at 17:10
• @_@ Why is there Jelly code – Leaky Nun Oct 8 '17 at 9:43
• cracked – Leaky Nun Oct 8 '17 at 9:51

Java (OpenJDK 8), 226 217 bytes (Cracked)

First ever code golf, probably very easy but it was a fun challenge!

String d(){int h=3609000-5055+911,m=557558,s=15441301-157*10000;String d="0"+h*2+""+m*20+""+s*7,x="",y;for(int g=0;g<d.length();g+=3){y="";for(int e=0;e<3;e++)y+=d.charAt(e+g);x+=(char)Integer.parseInt(y);}return x;}

Try it online!

• Your TIO doesn't work. You might want to change the return new Main().d(); to System.out.print(new Main().d()); in the main-method. – Kevin Cruijssen Oct 9 '17 at 12:47
• @KevinCruijssen Thanks for the heads up! – Luke Stevens Oct 9 '17 at 13:12
• – milk Oct 9 '17 at 21:57

dc, 148 bytes (Cracked)

6 93 3 9 2 2**+*+483622 1 2 3 3*+3*+89 47*+*+3 5 2* 269 158 9**107 97*2 4*++2 3 3*+42 14 2**+*+5*+5 2148 1 6 2*+*+68262 5 280 7 2 3 3*+5 2**+*+*+*+P

Try it online!

It is rather simple, but I hope it will be at least a little fun to solve :з

JavaScript, 119 bytes (ES6), Cracked

A function returning a string. Quite long and not so hard, but hopefully fun.

_=>(+{}+['H'])[+[3]]+(+[][[]]+[])[+!!3]+(+[][[]]+['y'])[3]+(+[][[]]+['s'])[-~2]+(~![]+['t'])[2]+(+[][[]]+[])[+!!3]+'ck'

"Haystack" demo

let f =

_=>(+{}+['H'])[+[3]]+(+[][[]]+[])[+!!3]+(+[][[]]+['y'])[3]+(+[][[]]+['s'])[-~2]+(~![]+['t'])[2]+(+[][[]]+[])[+!!3]+'ck'

console.log(f())

• Cracked. The jsfuck github README.md helped a lot. – the default. Oct 8 '17 at 8:16

Python 2.7.2, 103 / 117 bytes, Cracked

Function Version (117 bytes):

def e():
a,b,s=20070763850923833476353301471991752,0b1010100010010011,""
while a>0:
s=chr(a%b)+s
a//=b
print s

Program Version (103 bytes):

a,b,s=20070763850923833476353301471991752,0b1010100010010011,""
while a>0:
s=chr(a%b)+s
a//=b
print s

This should print Haystack well. Tested on Python Fiddle.

Btw this is the first attempt.

Not sure if the program version is counted as a snippet, so I put both versions here.

• – jacobly Oct 9 '17 at 4:01

Python 2.7.10 with Numpy 1.12.1, 208 209 bytes (cracked)

It appears that there is a Needle and a Haystack in Numpy! Here is the Haystack; see if you can find the Needle. I hope you have as much fun searching for the Needle as I had hiding it.

import numpy
print "".join([dir(numpy)[int(i)][1-0] for i in numpy.poly1d([-1*1433/252e1,-3232/1920.,4026./72/2/3.,613/(6*4.)*1,-4723./1.8e2,-9763/120.,-2689/(-1+5*17.),1+138*.4*2])(numpy.arange(-12/3,13%9))])

It outputs as specified:

Haystack

You can repl.it.

• Not that it really matters, but this is 209 bytes, not 208 – caird coinheringaahing Oct 8 '17 at 20:12
• – jacobly Oct 9 '17 at 11:32

Java 8, 321 bytes, Cracked

v->{String h="Haystack";int x=-7;return x<0?h:new String(new java.math.BigInteger(new byte[]{(byte)((~-~-~-~-~-~-~-~-~-~1^-x++*x)+151),new Byte("2"+"1+\"0+\"".length()+(x=h.length()*4/x)+"-x-7")}).toByteArray())+(new StringBuffer("hidden".substring(++x%3^4,--x-x--).replaceFirst("dd","e"+(char)(x*211%+93))).reverse());}

Try it here.

v->{
String h="Haystack";
int x=-7;
return x<0?
h
:
new String(new java.math.BigInteger(new byte[]{
(byte)((~-~-~-~-~-~-~-~-~-~1^-x++*x)+151),
new Byte("2"+"1+\"0+\"".length()+(x=h.length()*4/x)+"-x-7")
}).toByteArray())
+(new StringBuffer("hidden".substring(++x%3^4,--x-x--)
.replaceFirst("dd","e"+(char)(x*211%+93))
).reverse());
}

Not sure if it's too long/hard.. Then again, Java in general is pretty long to begin with, so hiding the 'Needle' properly of course increases the byte-count quite a bit..
If no one cracks it, I'll add some spoiler-tips later on.

• The TIO has one fewer character, but cracked either way. – jacobly Oct 9 '17 at 19:44

Ruby, 185 bytes, cracked by cab404

x='yGwztsPXhxDkBKlCYdFjQnpUROfoHvqmTgbaJSLcEiZrIAuMVNW'
s="n=x.to_i 36;x.bytjs.jach_cons(3){|a,b,c|n+=n*b%c;n*=a^b};puts n%8675309==1388649 ?'Njjdlj':'Haystack'"
eval s.tr ?j,s.size.chr

Try it online!

I'll try to come up with something sneaky, but for now here's a try at "simple but obnoxious."

• – cab404 Oct 11 '17 at 3:43
• that was fun ^^ – cab404 Oct 11 '17 at 14:24
• Well done! Glad brute force wasn't too boring. – histocrat Oct 11 '17 at 16:56

Brain-Flak, 188 bytes (Cracked)

I only just saw Funky Computer Man's answer As I posted this.

It is somewhat obfuscated.

((((((((((()()()){}){}()){}){}()){}()))<({}[(()()()()){}])(([[]]({})<>)<>)>((()()())){}{})[()]))<[[]()]>((()){}){}((){}[][(<>){}<>])(<>){}(({}<>()[()])[(((()()()){}<[()]>)<(()){}>{}){}()])

Try it online!

Intended solution, 96 bytes:

((((((((((()()()){}){}()){}){}()){}()))<({}[(()()()()){}])(([[]]({})<>)<>)>((()()())){}{})[()]))<[[]()]>((()){}){}((){}[][(<>){}<>])(<>){}(({}<>()[()])[(((()()()){}<[()]>)<(()){}>{}){}()])((((((((()()()){}){}){}()){}){}()<>)<>)(()()()){}())<>(((({}[()]<>)()))[(((()()()){}())()){}{}])
(((((((( (()()()){}){}  ){}){}()){}()))      ()()                   <>)     (()()()) {}    () ) <      >((()      ((){}    <>)     )   )  (({}        )[(((()()  ){}  ()  )  () {}   ){}()])

Try it online!

• You mean somewhat obfuscated beyond just normal Brain-Flak obfuscation. – Gryphon Oct 9 '17 at 13:33
• @Gryphon Yes, I added some extra bits. – H.PWiz Oct 9 '17 at 15:41
• Cracked. – Nitrodon Oct 15 '17 at 0:15

T-SQL, 757 characters CRACKED

Apologies for deleting my previous answer--I edited it too many times as I obfuscated, and didn't want to give anything away. :)

In any case, obfuscating in SQL is a bit difficult, unless you want to do crazy stuff like this, and I wasn't that invested.

Also, I unabashedly do not apologize for naming my variables after Dota.

SQL Fiddle

create table a(l int,c int)
insert into a values (1,10),(2,1),(3,8),(4,0)
go
;CREATE FUNCTION b(@ varchar(max)) returns varchar(max) as
begin return 'char('+@+'),'''','end
go
;CREATE FUNCTION h(@ varchar(max),@a varchar(max), @b varchar(max), @c varchar(max), @d varchar(max), @e varchar(max), @f varchar(max), @g varchar(max), @h varchar(max))
returns varchar(max) as
begin
return replace(replace(replace(replace(@,@a,@b),@c,@d),@e,@f),@g,@h)
end
declare @x varchar(max),@ int=1,@y varchar(99)=''
,@D varchar(4)='Ha',@O varchar(4)='ys'
,@T varchar(3)='ta',@A varchar(4)='ck'
WHILE @<=4
BEGIN
set @y+=(SELECT dbo.b(c+100)from a where l=@)+' '
set @+=1
END
SELECT @x='select
left(dbo.h('''+@D+@O+@T+@A+''','+ left(@y,len(@y)-1) +'),char(56))'
execute(@x)

If this is the easiest answer in this thread, you're probably right. :P It's hard to trick SQL.

• shouldn't 'haystack' be 'Haystack'? – cab404 Oct 11 '17 at 1:58
• SQL doesn't handle capitalization very nicely (unless you specifically define the schema that it's supposed to use for the letters). I opted not to. :P – phroureo Oct 11 '17 at 2:55
• @phroureo The spec does explicitly state that it must be capitalized correctly. – LyricLy Oct 11 '17 at 3:51
• Alright, I fixed the code above (although I didn't necessarily fix the SQL Fiddle, since it works the same). – phroureo Oct 11 '17 at 15:54
• cracked (I'm sorry...) – Robert Fraser Oct 15 '17 at 10:53

Ly, 40 bytes, cracked

(78)"e"&p"Ha"s"yst"l"ck"&o(100)"l"l'&'o;

Try it online!

Oh boy, another Ly CNR submission. These haven't worked very well historically (possibly due to me and not the language), but we'll see how this fares and today is no exception.

Solution:

(78)"e"sl(100)"l"l&o;, remove XXXXXX XXXXX XXXXXX X X with seven leading spaces

Java, 345 bytes, Cracked

import java.util.*;interface Main{static void main(String[]args){Stack<Hay>s=new Stack();s.add(new Needle());for(int i=0;i<1000;i++)s.add(new Hay());System.out.println(s.get(s.indexOf(new Hay())+1).a);}}class Needle extends Hay{{a="Needle";}}class Hay{String a="Haystack";public boolean equals(Object o){return getClass().equals(o.getClass());}}

Try it online!

Really long and probably easy to crack, but at least it's got a Stack<Hay>!

• very nice one! but yes, pretty easy to crack. – Titus Oct 20 '17 at 12:28

TI-BASIC, 119 bytes (Safe)

Output stored in Ans.

"TIBASIC→Str1
length(Ans→X
Str1
For(I,X,2(7-4not(X-1
End
sub(Ans,1+X,length(Ans)-X

Solution

Remove characters from Str1 to give it a length of 1.

"C→Str1
length(Ans→X
Str1
For(I,X,2(7-4not(X-1
End
sub(Ans,1+X,length(Ans)-X

PHP, 44 bytes, Cracked

fairly easy to crack; but I like it.

for($i=~1;$c=H_aNyesetdalcek[$i+=2];)echo$c;

Run with -nr or try it online.

Aceto, 154 bytes (Safe)

27\'dNU   QJi9MLJ€{{x(}]J{'!o∑€xiDQxsJ(]sicpicp1.2sJJicp90I.2+D/edxi-'>xd80J0IJicx'NIx5sJsJidcpIcpL7sssJicpei7+ UUdJicpLI7sJicpx'p\p9*coJcU'p+\p

Try it online!

'N'ed'd80J0IJic'eUpppppp Try it online!

Explanation:
<space>*2 - Two spaces for the hilbert curve to work right
'N pushes 'N' onto the stack
'e pushes 'e'
d duplicates it
'd pushes d
80 pushes 8, 0
J concats top two values
0I pushes 0, pops, increments, pushes back on, net effect: pushes 1
J concats to '108'
i converts to integer
c pops and pushes ascii equiv on stack
'e pushes 'e' (again)
U reverses the stack
and the p's print out the stack