PRINSEC - Editorial

PRINSEC

Contest
Practice

Author: sigma_g
Tester: multiple, see announcement
Editorialist: sigma_g

DIFFICULTY:

EASY

PREREQUISITES:

Bit operations

PROBLEM

Print YES if certain values of (x,y) matches a given set of tuples otherwise print NO.

Buggy code plain text

Pastebin

QUICK EXPLANATION

"Spoiler

You need to get (x,y)=(2,11) to get a wrong output. You can manipulate r via some quick bit operations to get r=25.

EXPLANATION

Step 1

Note that there is a stray YEZ the output. That is the bug in the code. So, we now know that we need to trigger x = 2 and y = 11.

Step 2

This implies that (r ^ 3) & (r ^ 31) == 3 and (r ^ 18) | (r ^ 16) == 4. Also, we know that r is less than 32, so it will be of 5 bits.

Step 3

We have two equations and we can satisfy them bit-by-bit. That is to say, for each bit of r, check if it’s being 0 or 1 can satisfy both the equations. Building r bitwise we’ll get 11001, which is 25.

SOLUTIONS:

Text submission.

Setter's Solution

25

1 Like