31
\$\begingroup\$

Inspired by this challenge, which got closed. This is meant to be an easier, but no less interesting version of that.

This is the cops thread of a challenge. For the robbers thread, see here.

Cops will provide a program/function and a flag. Robbers will try to guess a password such that, when the password is given to the cop's program, the flag is outputted.

Basic rules

  • The language used should be provided.
  • The flag, which can be an integer, string, or value of any other type, should be provided.
  • The flag may be printed to STDOUT, returned from a function, or outputted using any of the other standard output methods, as long as you specify how it will be outputted.
  • The program/function can take the password through STDIN, as a function argument, or using any of the other standard input methods, as long as you specify how the it will be inputted.
  • A free online compiler/interpreter should also be linked, preferably with the cop's code already pasted in and ready to run.

Some more rules

  • There must be at least one valid password that causes your program to return the flag, and you should know at least one of those passwords when posting your answer.
  • In case of a function submission, the cop should also include a full runnable program including the function either in the answer or in the linked online compiler/interpreter.
  • If it is at all ambiguous what the type of the flag is, it must be specified.
  • If a cop's description of the output is ambiguous (e.g. "HashSet(2, 1) should be printed"), robbers are allowed take advantage of that (e.g. print the string "HashSet(2, 1)" instead of an actual hashset)
  • Forcing robbers to simply brute force the password is not allowed.
  • The program must take input, and must output the flag when given the correct password. When not given the correct password, you are free to error, output something else, or immediately terminate. If your program never halts if given the wrong password, you must tell robbers of this behavior so no one waits around for the program to output something.

Cops's score will be the number of bytes their code takes up.

Cop answers will be safe if they haven't been cracked for two weeks.

Example

Cop:

Scala, 4 bytes

x=>x

Flag: Yay, you cracked it! (an object of type String is returned from the lambda above) Try it online!

Robber:

Password: the string "Yay, you cracked it!" Try it online!

Find Uncracked Cops

<script>site='meta.codegolf';postID=5686;isAnswer=false;QUESTION_ID=213962;</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>

\$\endgroup\$
17
  • 5
    \$\begingroup\$ This is already explicitly mentioned in the challenge, but here is the meta post from Loopholes that are forbidden by default about using cryptographic functions in CnR challenges. \$\endgroup\$ – Arnauld Oct 22 '20 at 17:56
  • 1
    \$\begingroup\$ May we specify multiple output formats at once; that is, specify that STDOUT must be a and STDERR must be b? \$\endgroup\$ – HyperNeutrino Oct 22 '20 at 18:23
  • 4
    \$\begingroup\$ @SunnyMoon Sure, you can tell robbers that the password is a multiple of 34. Whether it's wise to leave robbers that clue, I don't know :) \$\endgroup\$ – user Oct 22 '20 at 20:36
  • 4
    \$\begingroup\$ What is your definition of cryptographic functions? \$\endgroup\$ – the default. Oct 24 '20 at 12:08
  • 2
    \$\begingroup\$ This challenge seems to amount to just do cryptography without using cryptography. \$\endgroup\$ – Wheat Wizard Oct 25 '20 at 12:09

39 Answers 39

1
2
2
\$\begingroup\$

BrainF***, 22 bytes, Cracked by Cinaski

+++++[>,[--->+<]>.<<-]

Try it online!

The flag is wEe0H with nothing else. This shouldn't be too hard.

\$\endgroup\$
6
  • \$\begingroup\$ I made sure the flag would allow for a valid password \$\endgroup\$ – SuperPizz Feb 12 at 1:08
  • \$\begingroup\$ Wait i'm unsure did you forget to remove the password from the try it online link? \$\endgroup\$ – RezNesX Feb 12 at 7:50
  • \$\begingroup\$ Maybe? I didn't look into that. \$\endgroup\$ – SuperPizz Feb 12 at 15:03
  • \$\begingroup\$ cracked \$\endgroup\$ – Cinaski Feb 12 at 16:09
  • \$\begingroup\$ @SuperPizz You did leave the password in, but I edited in a link without it and anyway, Cinaski has cracked your answer. Btw, you should add "Cracked" to the header of your answer, with a link to the robber answer, so people know it's cracked. \$\endgroup\$ – user Feb 12 at 16:44
1
\$\begingroup\$

JavaScript (SpiderMonkey), 52 bytes, Cracked by r3mainer

i=>(a=+i,a<a/a?a/a<-a?1/a<a:a*a>1:1<a*a?a*a<a:1/a<a)

Try it online!

Expect output is true.

Input via parameter, output via return value. Global values should not be configured before the function execute. (For example, Object.defineProperty(globalThis, 'a', { get() { return ...; }, set() { return true; } }) is not valid.)

This one could be quite easy. I expected it will be cracked in 30 min...

\$\endgroup\$
2
  • \$\begingroup\$ Yes, it was quite simple in the end :-) Cracked \$\endgroup\$ – r3mainer Oct 26 '20 at 8:21
  • \$\begingroup\$ Yeah, pretty much :-D \$\endgroup\$ – r3mainer Oct 26 '20 at 8:39
1
\$\begingroup\$

C (x86-64), 100 bytes, cracked by @the-default.

This will survive until someone figures out how to run Xorshift in reverse. (So probably not very long!). Requires a key of 8 characters as a command line argument. The flag is CodeGolf followed by a line break (and nothing else before or after). Liable to crash if the key is missing or less than 8 characters in length.

main(int a,char**b){for(unsigned long *x=*++b,i=59295;i--;*x^=*x<<13,*x^=*x>>7,*x^=*x<<5);puts(*b);}

Try it online!

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

Ruby, 39 bytes, cracked by @EricDuminil

p eval($<.read.tr'Scfpvy.:?\'"%<`(',$/)

Try it online!

Here's hoping I've managed to close the backdoor that @Sisyphus exposed in the previous version. As before, input is via STDIN and the flag is """\n (with \n representing a trailing newline) printed to STDOUT. Nothing is printed to STDERR.


My password: Try it online! Same idea as the crack but somewhat different implementation.

\$\endgroup\$
2
  • \$\begingroup\$ cracked. Not sure if it was the intended solution. \$\endgroup\$ – Eric Duminil Oct 26 '20 at 21:52
  • 1
    \$\begingroup\$ Very interesting. I spent about 2h in order to find a solution which was very close to yours. I didn't like the fact that the methods' ID were hardcoded, and would only work on TIO and not on my computer. So I spent another 2h, trying to find a reliable way to access the methods. Congrats for the interesting challenge BTW: it was, to me at least, just the right balance between frustrating and fun. \$\endgroup\$ – Eric Duminil Oct 27 '20 at 10:46
1
\$\begingroup\$

R, 67 bytes, cracked by pppery

function(x) with(x, is.finite(a) && !is.finite(b) && is.nan(a + b))

Try it online!

The flag is TRUE. That is, find x such that f(x) is TRUE.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Cracked \$\endgroup\$ – pppery Oct 28 '20 at 15:36
1
\$\begingroup\$

R, 66 bytes, Cracked by Dominic van Essen

function(x) with(x, is.finite(a) && is.finite(b) && is.nan(a + b))

Try it online!

This is a slight (but significant) modification of my previous post. The flag is TRUE. That is, find x such that f(x) is TRUE.

Intended solution

Try it online! There are no two finite finite numbers that add to NaN. So we have to exploit the use of with. with uses the the contents of x to evaluate the expression. So simply redefine the function && to be unconditionally TRUE.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ I assume that this is not the intended solution... although I can't immediately find a way to rule it out... \$\endgroup\$ – Dominic van Essen Oct 28 '20 at 22:35
  • \$\begingroup\$ Nice! Not exactly my solution, but still a valid solution. \$\endgroup\$ – Paul Oct 29 '20 at 0:03
1
\$\begingroup\$

Racket, 202 bytes

#lang racket

(define (h z)
  (when (procedure? z) (error "you lose"))
  (define a (λ (x) (not x)))
  ((λ (f) (call/cc (λ (k) (k (or (a z) (set! a ((eval f) k))))))) z)
  (and z (print (a "hello"))))

The flag is hello. The password (in the form of a quote-string) is passed as the argument to the h function.

Try it online!

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

Zsh + coreutils, 213 bytes

n=$(shuf -n1 -i0-9999999);out=$( (eval "$(tr -dc '\t\n -/:-@[-`{-~')") );s=$((n**.5));i=1;p=Yes;while [[ "$i" -le "$s" ]];do;i=$((i+1));if [[ $((n%i)) -eq 0 ]];then;p=No;break;fi;done;[[ "$p" = "$out" ]]&&echo Win

Must be run as root on a typical modern Linux system. (so no TIO link). Telling you why would spoil the challenge.

Flag is Win with a trailing newline, printed to stdout.

\$\endgroup\$
2
  • \$\begingroup\$ Does the password have to work consistently? \$\endgroup\$ – the default. Nov 8 '20 at 16:12
  • 1
    \$\begingroup\$ @thedefault. yes \$\endgroup\$ – pxeger Nov 8 '20 at 16:15
0
\$\begingroup\$

Python 3, 958 bytes

x=[(9,23),(10,24),(10,25),(11,23),(11,24)]
def f(g):
    h=g.copy()
    for move in range(30):
        n=[]
        for i in range(12):
            n.append([])
            for j in range(36):
                c=0
                for (a,b)in[(-1,-1),(-1,0),(-1,1),(0,-1),(0,1),(1,-1),(1,0),(1,1)]:
                    if i+a>=0 and i+a<12 and j+b>=0 and j+b<36:
                        c+=h[i+a][j+b]
                if h[i][j]==0 and c==3:
                    n[i].append(1)
                elif h[i][j]==0:
                    n[i].append(0)
                elif h[i][j]==1 and c!=2 and c!=3:
                    n[i].append(0)
                elif h[i][j]==1:
                    n[i].append(1)
        h=n.copy()
    for i in range(12):
        for j in range(36):
            if g[i][j]!=h[i][j]:
                if not((i,j)in x):
                    print('N')
    for (i,j)in x:
        if g[i][j]==h[i][j]:
            print('N')
    print('Y')

Try it online! Flag: Y. The password is taken through input to f, so to run the code just edit the last line f([]).

Solution:

The code simply runs Conway's game of life on a finite grid, and tests whether the result after 30 ticks is the original grid with a particular set of 5 cells toggled. The solution is:

Gosper's glider gun. [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1], [1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]] Try it online!

New contributor
littlecat is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
\$\endgroup\$
2
  • 1
    \$\begingroup\$ There's no need to post the solution right now, you can do that after your answer is cracked or it's safe \$\endgroup\$ – user Feb 19 at 18:37
  • 1
    \$\begingroup\$ Welcome to Code Golf! Nice first answer. \$\endgroup\$ – Redwolf Programs Feb 19 at 19:01
1
2

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.