27
\$\begingroup\$

This is a challenge. For the robbers thread, go here.

This challenge involves two OEIS sequences chosen by the cops -- S1, S2 -- and how well those sequences can be golfed and obfuscated.

The Cops' Challenge

Your challenge as a cop is to pick a freely available language, and two OEIS sequences. Then, write code A in that language that takes input n and produces S1(n). When that code is modified by a Levenshtein distance of X characters (with X no more than 0.5 * (length A)), and turned into code B in the same language, it must then produce S2(n). You must actually write this code B, but don't reveal it until your challenge is safe (see below).

The cops' submissions must include the language name, the full code A, the byte-count of A, the X value of how many changes to get to their secret B code, and the chosen S1 and S2 sequence numbers. You can choose whether each sequence is 0-indexed or 1-indexed, but please specify that in your submission.

To crack a particular submission, robbers must come up with a program C in the same language (and version) that produces S2(n) and is Y character changes away from A (with Y <= X). Robbers do not necessarily need to find the exact same B code that the cop (secretly) produced.

Winning and Scoring

If your cop answer has not been cracked within 7 days (168 hours), you may reveal your own B solution, at which point your answer is considered 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. If your answer does get cracked, please indicate this in the header of your answer, along with a link to the corresponding robber's answer.

Cops win by having the uncracked submission with the shortest A. If tied, then the smallest X will be used as tie-breaker. If still tied, the earlier submission will win.

Further Rules

  • You must not use any built-ins for hashing, encryption, or random number generation (even if you seed the random number generator to a fixed value).
  • Either programs or functions are allowed, but the code must not be a snippet and you must not assume a REPL environment.
  • You may take input and give output in any convenient format. The input/output methods must be the same for both sequences.
  • The definitive calculator for the Levenshtein distance for this challenge is this one on Planet Calc.
  • In addition to being a CnR challenge, this is so all usual golfing rules apply.
\$\endgroup\$
  • \$\begingroup\$ Also, make sure if you change something in this question, that you update the robbers one. \$\endgroup\$ – mbomb007 Feb 13 '17 at 17:36
  • \$\begingroup\$ What if a cop names a function/variable really big with respect to the actual code generating the sequence? It'll be possible to create any sequence in this case with its lev distance being less that (0.5*len(A)) \$\endgroup\$ – hashcode55 Feb 13 '17 at 17:38
  • \$\begingroup\$ @hashcode55 Two things -- 1) that's not likely going to be a good candidate for winning the cops' thread. 2) if it's enormous like that, it also gives a good leeway for the robbers to crack it. \$\endgroup\$ – AdmBorkBork Feb 13 '17 at 17:40
  • 1
    \$\begingroup\$ "this is code-golf so all usual golfing rules apply" Does this mean that code A must be golfed as much as possible, or can it be intentionally written in a too verbose/awkward way to make it more similar to code B? \$\endgroup\$ – smls Feb 13 '17 at 18:05
  • 7
    \$\begingroup\$ Search un-cracked answers \$\endgroup\$ – mbomb007 Feb 13 '17 at 23:02

16 Answers 16

10
\$\begingroup\$

Brain-Flak, 28 bytes, Distance of 4, A002817, A090809 Cracked

This answer uses 1-indexing

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

Try it online

For anyone interested there are 27475 valid Brain-Flak programs with Levenshtein distance 4 from this program and 27707 with distance 4 or less. So a brute force solution would be feasible on a consumer grade computer.

\$\endgroup\$
  • \$\begingroup\$ It'd probably be shorter and quicker to read if you have X = 4 instead of Levenshtein distance of 4. \$\endgroup\$ – mbomb007 Feb 13 '17 at 19:17
  • 1
    \$\begingroup\$ @mbomb007 I personally get a bit confused when challenges use a bunch of letter variables to stand in for things I was trying to avoid confusion. I have made it shorter now, hopefully without causing any confusion. \$\endgroup\$ – Sriotchilism O'Zaic Feb 13 '17 at 19:19
  • \$\begingroup\$ shrug. If everyone read the question, they should get it. X is really the only variable they need to know. \$\endgroup\$ – mbomb007 Feb 13 '17 at 19:20
  • \$\begingroup\$ @mbomb007 Although, the question also asks for a byte count. \$\endgroup\$ – DLosc Feb 14 '17 at 4:13
  • 1
    \$\begingroup\$ Cracked! \$\endgroup\$ – DJMcMayhem Feb 19 '17 at 7:31
6
\$\begingroup\$

7, 33 characters, 13 bytes, X = 10, A000124A000142, Safe

171720514057071616777023671335133

Try it online!

The Levenshtein distance is measured in terms of characters, so I've written the program in terms of the characters it contains above (and Try it online!, including the language itself, is happy to run programs encoded in ASCII). However, the program is stored in disk using 7's sub-byte encoding, meaning that the program itself is actually the following hexdump (thus 13 bytes long):

00000000: 3cf4 2982 f1ce 3bfe 13dc b74b 7f         <.)...;....K.

(Because the Levenshtein distance is measured in terms of characters, you aren't necessarily adding/deleting/changing 10 bytes here, so it's probably best to work with the original ASCII.)

The program as written implements A000124 (triangular numbers + 1); any crack must implement A000142 (factorials). Both programs take input from stdin (as decimal integers), write their output to stdout, and treat an input of 1 as meaning the first element of the sequence (and an input of 2 as the second element, etc.).

Hopefully the very high X value will stop people brute-forcing the program, this time (which is always a risk with cops-and-robbers entries in 7).

The solution

177172051772664057074056167770236713351353

Try it online!

Differences from the original:

17 172051     405707 1 61677702367133513 3
177172051772664057074056167770236713351353

I don't have explanations prepared for how these work, so it's going to take me a while to get an explanation up, as I'm going to have to figure it out from almost-scratch. Hopefully there will be an explanation eventually.

\$\endgroup\$
5
\$\begingroup\$

Pyke, Levenshtein distance of 1, A036487, A135628.

Cracked!

X*e

Try it here!

\$\endgroup\$
4
\$\begingroup\$

Perl 6, 10 bytes, X = 1, A000012A001477

Cracked!

*[0]o 1***
  • S1 = A000012 = 1,1,1,1,1,... = The all 1's sequence. (0-indexed)

  • S2 = A001477 = 0,1,2,3,4,... = The nonnegative integers. (0-indexed)

Try it online!

Confirmed to work with Perl 6 release 2017.01, and with the Perl6 version running on TIO.

(A could be further golfed to 1*** – I hope it it's also allowed as it is.)

\$\endgroup\$
3
\$\begingroup\$

Perl 6, 13 bytes, X = 1, A161680A000217

Safe!

{[+] [,] ^$_}
  • S1 = A161680 = 0 0 1 3 6 10 15 21... = Zero followed by the triangular numbers.
  • S2 = A000217 = 0 1 3 6 10 15 21 28 ... = The triangular numbers.
  • Zero-indexed.

Try it online!

(Confirmed to work with the Perl 6 version running on TIO.)

Solution

{[+] [\,] ^$_}

How the original works:

{           }  # A lambda.
          $_   # Lambda argument.                     e.g. 4
         ^     # Range from 0 to n-1.                 e.g. 0, 1, 2, 3
     [,]       # Reduce with comma operator.          e.g. 0, 1, 2, 3
 [+]           # Reduce with addition operator.       e.g. 6

How the solution works:

{            } # A lambda.
           $_  # Lambda argument.                     e.g. 4
          ^    # Range from 0 to n-1.                 e.g. 0, 1, 2, 3
     [\,]      # Triangle reduce with comma operator. e.g. (0), (0,1), (0,1,2), (0,1,2,3)
 [+]           # Reduce with addition operator.       e.g. 10

Exploits the fact that numeric operators like addition treat a list as its number of elements, so in the example the sum is 1 + 2 + 3 + 4 = 10.

And yeah, the "Reduce with comma operator" no-op in the original is kinda skirting the code-golf rules, but I prefer to look at it as a silly algorithm which has been golfed as much as possible (whitespace etc.) for what it is... :)

\$\endgroup\$
  • \$\begingroup\$ This is begging to be brute forced, if I had the time or the inclination (and the knowledge of perl). \$\endgroup\$ – Rohan Jhunjhunwala Feb 19 '17 at 1:53
  • \$\begingroup\$ This has survived long enough to be marked as safe \$\endgroup\$ – fəˈnɛtɪk Feb 21 '17 at 14:13
2
\$\begingroup\$

Jelly, 11 bytes, X = 5, A005185A116881

ịḣ2S;
1Ç¡ḊḢ

This is a full program that takes an integer as command-line argument and prints an integer.

Both sequences are indexed as on OEIS, i.e, A005185 is 1-indexed and A116881 is 0-indexed.

Try it online!

\$\endgroup\$
2
\$\begingroup\$

Javascript, 41 bytes, Distance of 3, A061313, A004526, Cracked

f=x=>{return x>1?x%2?f(x+1)+1:f(x/2)+1:0}

Try it Online

Uses 1 based indexing, solution uses 0 based indexing.

Once again, a different solution...

f=x=>{return x>1?x<2?f(x-1)+1:f(x-2)+1:0}
\$\endgroup\$
  • \$\begingroup\$ Cracked. \$\endgroup\$ – Dennis Feb 13 '17 at 21:25
  • 3
    \$\begingroup\$ By the way, you shouldn't use tio.run permalinks. They will stop working soon. \$\endgroup\$ – Dennis Feb 13 '17 at 21:26
  • \$\begingroup\$ ^ Use tio.run/nexus instead. \$\endgroup\$ – mbomb007 Feb 13 '17 at 22:56
1
\$\begingroup\$

Perl 6, 19 bytes, X = 1, A000045A000035

Cracked!

{(0,1,*+*...*)[$_]}
  • S1 = A000045 = 0 1 1 2 3 5 8 13 21 34... = "Fibonacci numbers". (0-indexed)
  • S2 = A000035 = 0 1 0 1 0 1 0 1 0 1... = "Period 2". (0-indexed)

Try it online!

(Confirmed to work with the Perl 6 version running on TIO.)

\$\endgroup\$
  • \$\begingroup\$ Cracked. \$\endgroup\$ – Dennis Feb 14 '17 at 5:52
1
\$\begingroup\$

WolframAlpha, 18 bytes, X = 1

Cracked by math_junkie!

(sum1to#of n^1)*2&

Sometimes WolframAlpha will actually be able to display a pure function like this in functional form (other times it gets confused); but it can be cheerfully invoked with a given input—for example, (sum1to#of n^1)*2&@5 yields 30.

S1 = A002378 (pronic numbers)

S2 = A000537 (sum of the first n cubes)

Both sequences are 0-indexed.

\$\endgroup\$
1
\$\begingroup\$

Pyke, Levenshtein distance of 2, A008788, A007526

Cracked!

'th^

Try it here!

Let's get slightly harder shall we?

The first answer is 1 based and the crack is 0 based.

\$\endgroup\$
  • \$\begingroup\$ Cracked. \$\endgroup\$ – Dennis Feb 14 '17 at 21:20
1
\$\begingroup\$

Javascript, 15704 bytes, distance of 2, A059841 and A000004 - cracked

This solution is extremely long, so you can find the full code at this github gist.

The original answer (this one) is 1 indexed. (I know this is way too long, it is just for fun.)

\$\endgroup\$
  • \$\begingroup\$ Cracked. Also, adding absolutely useless code !+[]-(!+[]) isn't really in the spirit of the rules \$\endgroup\$ – fəˈnɛtɪk Feb 14 '17 at 20:59
  • \$\begingroup\$ Just so you know, this answer is causing some issues for the OP of this challenge. Apparently it causes the whole page to be blocked because it looks like sketchy JavaScript. Could you maybe put the code in an external link? (Gist, pastedump, etc) \$\endgroup\$ – DJMcMayhem Feb 14 '17 at 21:44
  • \$\begingroup\$ Actually, I've put it in a gist myself. If you would rather have the code somewhere else, feel free to edit it again if I've overstepped my bounds. \$\endgroup\$ – DJMcMayhem Feb 14 '17 at 21:50
  • \$\begingroup\$ I guess that the !+[]-(!+[]) does make it so that you can't just reverse the conversion. But some of the other garbage just makes it longer. The equivalent code is only 15640 bytes. \$\endgroup\$ – fəˈnɛtɪk Feb 14 '17 at 21:53
1
\$\begingroup\$

Brain-Flak, 16 bytes, Levenshtein distance of 4, A000217 and A002378 -- Cracked by Martin Ender!

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

Try it online!

This should be fairly easy to crack.

\$\endgroup\$
  • 1
    \$\begingroup\$ Cracked. \$\endgroup\$ – Martin Ender Feb 14 '17 at 23:05
  • \$\begingroup\$ @WheatWizard Oh, whoops, I didn't realize I forgot too. \$\endgroup\$ – DJMcMayhem Feb 16 '17 at 20:41
0
\$\begingroup\$

Javascript, 30 bytes, Distance of 4, A000290, A000079, -Cracked!

f=x=>{return x?2*x-1+f(x-1):0}

0-based indexing

@Kritixi Lithos's solution was actually different from mine

f=x=>{return x?f(x-1)+f(x-1):1}

Try it online

\$\endgroup\$
  • 1
    \$\begingroup\$ This is x**2 and not 2**x \$\endgroup\$ – Cows quack Feb 13 '17 at 19:54
  • \$\begingroup\$ I think it's A000290, not A000079. \$\endgroup\$ – betseg Feb 13 '17 at 19:55
  • \$\begingroup\$ @KritixiLithos it is supposed to be both. I changed the wrong sequence link on the top when I changed the other end. \$\endgroup\$ – fəˈnɛtɪk Feb 13 '17 at 20:00
  • \$\begingroup\$ Cracked \$\endgroup\$ – Cows quack Feb 13 '17 at 20:05
0
\$\begingroup\$

Javascript (ES6), distance is 1, A000079 and A000004 - cracked

as=function(){ return 2*2**((11)*-1*~arguments[0]/11-(4-(as+[]).length%89))-(as+[]).length%7}

The original answer (this one) is 0 based. Now that it has been cracked, here is the original B function:

as=function(){ return 2*2**((1^1)*-1*~arguments[0]/11-(4-(as+[]).length%89))-(as+[]).length%7}
\$\endgroup\$
0
\$\begingroup\$

Perl 6, 7 bytes, X = 2, A059841A001477

Cracked!

+(*%%2)
  • S1 = A059841 = 1 0 1 0 1 0 1 0... = "*Period 2: Repeat (1,0)". (0-indexed)
  • S2 = A001477 = 0 1 2 3 4 5 6 7... = "The nonnegative integers". (0-indexed)

Try it online!

(Confirmed to work with the Perl 6 version running on TIO.)

\$\endgroup\$
0
\$\begingroup\$

Java 7, Levenshtein distance of 4, A094683, A000290, Cracked

int x{double r=1;for(int i=0;i<42;i++)r=r/2+n/r/2;int k=(int)((int)n*(float)n/Math.pow(n,(Math.sin(n)*Math.sin(n)+Math.cos(n)*Math.cos(n))/2));return n%4%2==(int)Math.log10(Math.E)/Math.log((double)'H'-'@')?(int)r:k;}

0-indexed.
Try it here!

\$\endgroup\$
  • \$\begingroup\$ @LliwTelracs did that for the first 15 non-negative integers, see my updated answer. \$\endgroup\$ – peech Feb 14 '17 at 16:29
  • \$\begingroup\$ Cracked \$\endgroup\$ – fəˈnɛtɪk Feb 14 '17 at 17:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.