#P4154. Cracking the Obfuscated Binary Classification Algorithm
Cracking the Obfuscated Binary Classification Algorithm
Cracking the Obfuscated Binary Classification Algorithm
In this problem, you are given an obfuscated algorithm used in a mobile app for image recognition. The app takes an n‐bit binary string extracted from an image and, after Q operations, produces a classification result (either 0 or 1).
The obfuscated algorithm works on an array y[]
of length L (where L is at least max(u,v,s,d,e)+1) that is initially filled as follows: the first n bits are the input bits and the rest are zeros. Then Q lines of code are executed sequentially. Each line is of the form:
y[u] = (not (y[v] and y[s])) xor y[d] xor y[e]
Here, and
denotes the logical AND, xor
is exclusive OR, and not
inverts the bit (i.e. not 0 = 1
and not 1 = 0
).
The output of the algorithm is simply y[0]
after processing all Q lines.
Behind the scenes, the original classification function is much simpler. It extracts m bits of "effective information" from the input. Each effective bit is obtained as the XOR of a subset of input bits. Then, a Boolean function h is applied to these m bits via a lookup table of length \(2^m\) (each entry is either 0 or 1) to produce the result. To hinder reverse-engineering, the app also introduces noise: the final output of the obfuscated algorithm is flipped for some inputs, but the noise proportion does not exceed p (i.e. on at least \(2^n(1-p)\) inputs the obfuscated algorithm returns the "true" classification outcome).
Your task is to provide a cracked algorithm that expresses the classification function in a simplified form by:
- Choosing m subsets of \(\{0,1,\dots,n-1\}\). The i-th subset indicates which input bits are taken and XORed together to form the i-th effective bit.
- Defining a lookup table (a binary string of length \(2^m\)) for a function \(h\) such that, if the effective bits (after XOR computations) form a binary number \(v\), the cracked algorithm outputs \(h[v]\).
Your cracked algorithm must agree with the obfuscated algorithm on at least \(2^n(1-p)\) inputs. (It is guaranteed that none of the effective bits can be dispensed with – the function h necessarily depends on all m inputs.)
A valid cracked algorithm need not be unique. In this problem, you may output any cracked algorithm that meets the requirements. One acceptable approach is to use the first m bits as the effective bits and then, for each possible m-bit pattern, define \(h\) to be the majority value (over all \(2^{n-m}\) inputs sharing that prefix) of the obfuscated algorithm’s output.
Example
// Obfuscated algorithm (Q=2 lines): // Line 1: y[0] = (not (y[0] and y[1])) xor y[2] xor y[3] // Line 2: y[1] = (not (y[1] and y[2])) xor y[0] xor y[3]</p>// Input: n = 4, m = 2, Q = 2, p = 0.25 // Binary input string: 1010
// The cracked algorithm will consider the effective information as the first 2 bits (i.e. "10"). // It then precomputes a lookup table T[0..3] by simulating the obfuscated algorithm for all inputs with the corresponding first 2 bits and taking the majority vote. // Finally, it outputs T[2] (since "10" corresponds to 2).
inputFormat
The input begins with a line containing four values: n
(the length of the input binary string), m
(the number of effective information bits), Q
(the number of operations in the obfuscated algorithm), and p
(the maximum allowed noise proportion).
Then follow Q lines, each containing 5 integers: u v s d e
corresponding to an operation in the obfuscated algorithm.
The last line of the input contains a binary string of length n
representing the extracted features from an image.
outputFormat
Output a single bit (0 or 1) – the classification result produced by your cracked algorithm.
sample
4 2 2 0.25
0 0 1 2 3
1 1 2 0 3
1010
0