Change the Code, Change the Sequence: Cops

27

2

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.

AdmBorkBork

Posted 2017-02-13T17:22:14.660

Reputation: 41 581

Also, make sure if you change something in this question, that you update the robbers one. – mbomb007 – 2017-02-13T17:36:12.503

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)) – hashcode55 – 2017-02-13T17:38:46.787

@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. – AdmBorkBork – 2017-02-13T17:40:46.257

1"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? – smls – 2017-02-13T18:05:44.493

@smls Writing goofy code is fine. Obviously, different algorithms will be golfed differently. Just because there's a different algorithm that's shorter isn't an issue. Intentionally padding with spaces or comments is not okay, though. – AdmBorkBork – 2017-02-13T18:14:02.060

My usual question: if the language uses a bizarre encoding, is the Levenshtein distance measured using bytes or characters? – None – 2017-02-13T19:55:46.060

@ais523 I've only ever encountered Levenshtein in terms of characters, so that's what we're using here. I'll edit that in explicitly. – AdmBorkBork – 2017-02-13T20:01:10.897

@AdmBorkBork If the programs need to be golfed, that should be mentioned in the spec. Also, does this apply only for A or for B as well? – Dennis – 2017-02-13T20:44:09.200

7Search un-cracked answers – mbomb007 – 2017-02-13T23:02:41.820

Answers

10

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.

Post Rock Garf Hunter

Posted 2017-02-13T17:22:14.660

Reputation: 55 382

It'd probably be shorter and quicker to read if you have X = 4 instead of Levenshtein distance of 4. – mbomb007 – 2017-02-13T19:17:38.033

1@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. – Post Rock Garf Hunter – 2017-02-13T19:19:49.110

shrug. If everyone read the question, they should get it. X is really the only variable they need to know. – mbomb007 – 2017-02-13T19:20:38.593

@mbomb007 Although, the question also asks for a byte count. – DLosc – 2017-02-14T04:13:05.700

That's not defined as a "variable" with a letter assigned to it, though. – mbomb007 – 2017-02-14T14:24:33.033

"27707 with distance 4 or less" Surely this implies 232 valid programs with distance 2, right? I don't believe there are any at a distance of 1 or 3. – ETHproductions – 2017-02-17T22:54:31.447

@ETHproductions yes that is true. – Post Rock Garf Hunter – 2017-02-17T22:58:43.253

1Cracked! – James – 2017-02-19T07:31:24.817

6

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.

user62131

Posted 2017-02-13T17:22:14.660

Reputation:

5

Pyke, Levenshtein distance of 1, A036487, A135628.

Cracked!

X*e

Try it here!

Blue

Posted 2017-02-13T17:22:14.660

Reputation: 26 661

4

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.)

smls

Posted 2017-02-13T17:22:14.660

Reputation: 4 352

3

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... :)

smls

Posted 2017-02-13T17:22:14.660

Reputation: 4 352

This is begging to be brute forced, if I had the time or the inclination (and the knowledge of perl). – Rohan Jhunjhunwala – 2017-02-19T01:53:14.817

This has survived long enough to be marked as safe – fəˈnɛtɪk – 2017-02-21T14:13:07.053

2

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!

Dennis

Posted 2017-02-13T17:22:14.660

Reputation: 196 637

2

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}

fəˈnɛtɪk

Posted 2017-02-13T17:22:14.660

Reputation: 4 166

Cracked. – Dennis – 2017-02-13T21:25:24.670

3

By the way, you shouldn't use https://tio.run permalinks. They will stop working soon.

– Dennis – 2017-02-13T21:26:14.067

^ Use https://tio.run/nexus instead.

– mbomb007 – 2017-02-13T22:56:32.060

1

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.

Blue

Posted 2017-02-13T17:22:14.660

Reputation: 26 661

Cracked. – Dennis – 2017-02-14T21:20:08.687

1

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.)

smls

Posted 2017-02-13T17:22:14.660

Reputation: 4 352

Cracked. – Dennis – 2017-02-14T05:52:56.717

1

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.

Greg Martin

Posted 2017-02-13T17:22:14.660

Reputation: 13 940

Cracked! – math junkie – 2017-02-14T19:12:49.357

1

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.)

user54187

Posted 2017-02-13T17:22:14.660

Reputation:

Cracked. Also, adding absolutely useless code !+[]-(!+[]) isn't really in the spirit of the rules – fəˈnɛtɪk – 2017-02-14T20:59:49.570

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)

– James – 2017-02-14T21:44:16.257

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. – James – 2017-02-14T21:50:53.227

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. – fəˈnɛtɪk – 2017-02-14T21:53:09.590

1

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.

James

Posted 2017-02-13T17:22:14.660

Reputation: 54 537

1Cracked. – Martin Ender – 2017-02-14T23:05:38.330

@WheatWizard Oh, whoops, I didn't realize I forgot too. – James – 2017-02-16T20:41:19.393

0

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

fəˈnɛtɪk

Posted 2017-02-13T17:22:14.660

Reputation: 4 166

1This is x**2 and not 2**x – user41805 – 2017-02-13T19:54:50.327

I think it's A000290, not A000079.

– betseg – 2017-02-13T19:55:38.717

@KritixiLithos it is supposed to be both. I changed the wrong sequence link on the top when I changed the other end. – fəˈnɛtɪk – 2017-02-13T20:00:48.150

Cracked – user41805 – 2017-02-13T20:05:56.237

0

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}

user54187

Posted 2017-02-13T17:22:14.660

Reputation:

1

I was able to get my crack http://codegolf.stackexchange.com/a/109976/64505 to behave inconsistently between two different environments.

– fəˈnɛtɪk – 2017-02-13T21:12:37.503

0

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.)

smls

Posted 2017-02-13T17:22:14.660

Reputation: 4 352

1

Am I doing this right? http://codegolf.stackexchange.com/a/110001/60793

– Joey Marianer – 2017-02-14T04:26:17.910

0

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!

peech

Posted 2017-02-13T17:22:14.660

Reputation: 309

@LliwTelracs did that for the first 15 non-negative integers, see my updated answer. – peech – 2017-02-14T16:29:12.383

Cracked – fəˈnɛtɪk – 2017-02-14T17:03:54.860