ACSC 2026 Qualifier
Category: crypto
Problem #
Let \(p \in \mathbb P\) be prime, \(n \in \mathbb N\), and \(b \in \mathbb N\) with \(b \ll p\). Let \(v_1, \ldots, v_n \in_{\text{u.a.r.}} \{0, \ldots, p - 1\}\) and \(x_1, \ldots, x_n \in_{\text{u.a.r.}} \{0, \ldots, b\}\) be chosen uniformly at random. Define \(c \in \{0, \ldots, p - 1\}\) as \[ c = v_1 x_1 + \ldots + v_n x_n \mod{p}. \tag{1} \] Given \(p, b, v_1, \ldots, v_n, c\) determine \(x_1, \ldots, x_n\).
Solution #
Simple #
We rewrite equation (1) as
\[ v_1 x_1 + \cdots + v_n x_n + k p - c = 0 \tag{2} \]
for some unknown \(k \in \mathbb Z\). Now define the \((n + 2) \times (n + 2)\) matrix \(M\) over \(\mathbb Z\) as
\[ M = \begin{bmatrix} 1 & 0 & \cdots & 0 & 0 & w \cdot v_1 \\ 0 & 1 & \cdots & 0 & 0 & w \cdot v_2 \\ \vdots & \vdots & \ddots & \vdots & \vdots & \vdots \\ 0 & 0 & \cdots & 1 & 0 & w \cdot v_n \\ 0 & 0 & \cdots & 0 & 0 & w \cdot p \\ 0 & 0 & \cdots & 0 & -1 & w \cdot c \\ \end{bmatrix} \]
where \(w \in \mathbb Z_{>0}\), and consider the vector \(x\) with
\[ x = \begin{bmatrix} x_1 & \cdots & x_n & k & -1 \\ \end{bmatrix} . \]
Observe that for \(M\) and \(x\) we have
\[ \begin{align*} x M = &\begin{bmatrix} x_1 & x_2 & \cdots & x_n & 1 & w \cdot (\sum_{i = 1}^{n} v_i x_i + k p - c) \\ \end{bmatrix} \\ \stackrel{(2)}{=} &\begin{bmatrix} x_1 & x_2 & \cdots & x_n & 1 & 0 \\ \end{bmatrix} \end{align*} \]
Since \(xM\) is a relatively short vector we apply the LLL lattice basis reduction algorithm to \(M\) and hope to find it as a row of the result. A suitable \(w\) has to be guessed.
Centered #
Should this not produce a result we can try to construct an even shorter vector.
Define \(\delta = \lfloor b/2 \rfloor\), define \(y_i = x_i - \delta\) for every \(i \in \{1, \ldots, n\}\), and define \(c' \in \mathbb Z\) as
\[ c' = c - \delta \sum_{i = 1}^{n} v_i. \]
Observe that
\[ \begin{align*} \sum_{i = 1}^{n} v_i y_i + k p - c' &= \sum_{i = 1}^{n} v_i (x_i - \delta) + k p - c' \\ &= \sum_{i = 1}^{n} v_i x_i - \sum_{i = 1}^{n} v_i \delta + k p - c + \delta \sum_{i = 1}^{n} v_i \\ &= \sum_{i = 1}^{n} v_i x_i + k p - c \\ &\stackrel{(2)}{=} 0 . \tag{3} \end{align*} \]
Now define the \((n + 2) \times (n + 2)\) matrix \(M'\) over \(\mathbb Z\) as
\[ M' = \begin{bmatrix} 1 & 0 & \cdots & 0 & 0 & w \cdot v_1 \\ 0 & 1 & \cdots & 0 & 0 & w \cdot v_2 \\ \vdots & \vdots & \ddots & \vdots & \vdots & \vdots \\ 0 & 0 & \cdots & 1 & 0 & w \cdot v_n \\ 0 & 0 & \cdots & 0 & 0 & w \cdot p \\ 0 & 0 & \cdots & 0 & -1 & w \cdot c' \\ \end{bmatrix} \]
where \(w \in \mathbb Z_{>0}\), and consider the vector \(y\) with
\[ y = \begin{bmatrix} y_1 & \cdots & y_n & k & -1 \\ \end{bmatrix} . \]
Observe that for \(M'\) and \(y\) we have
\[ \begin{align*} y M' = &\begin{bmatrix} y_1 & y_2 & \cdots & y_n & 1 & w \cdot (\sum_{i = 1}^{n} v_i y_i + k p - c') \\ \end{bmatrix} \\ \stackrel{(3)}{=} &\begin{bmatrix} y_1 & y_2 & \cdots & y_n & 1 & 0 \\ \end{bmatrix} \end{align*} \]
Since \(\lceil -b/2 \rceil \le y_i \le \lceil b / 2 \rceil\) whereas \(0 \le x_i \le b\) for every \(i \in \{1, \ldots, n\}\), \(y M'\) will usually be shorter than \(x M\). We apply the LLL lattice basis reduction algorithm to \(M'\) and hope to find \(y M'\) as a row in the result. We can then trivially reconstruct \(x_1, \ldots, x_n\).
Implementation #
#!/usr/bin/env sage
def solve_simple(p, n, b, v, c):
# construct M
w = 2 ** ((n // 2) + 5) * b
M = Matrix(ZZ, n + 2, n + 2)
for i in range(n):
M[i,i] = 1
M[i,n+1] = w * v[i]
M[n,n+1] = w * p
M[n+1,n] = -1
M[n+1,n+1] = w * c
L = M.LLL()
# check for potential solution
for row in L:
if not (row[n+1] == 0 and abs(row[n]) == 1):
continue
if row[n] == -1:
row *= -1
x = row[:n]
if not all(0 <= xi <= b for xi in x):
continue
if (sum(vi * xi for vi, xi in zip(v, x)) - c) % p:
continue
return list(x)
return None
def solve_centered(p, n, b, v, c):
# construct M_prime
w = 2 ** ((n // 2) + 5) * b
delta = b // 2
c_prime = c - delta * sum(v)
M_prime = Matrix(ZZ, n + 2, n + 2)
for i in range(n):
M_prime[i,i] = 1
M_prime[i,n+1] = w * v[i]
M_prime[n,n+1] = w * p
M_prime[n+1,n] = -1
M_prime[n+1,n+1] = w * c_prime
L = M_prime.LLL()
# check for potential solution
for row in L:
if not (row[n+1] == 0 and abs(row[n]) == 1):
continue
if row[n] == -1:
row *= -1
y = row[:n]
x = [yi + delta for yi in y]
if not all(0 <= xi <= b for xi in x):
continue
if (sum(vi * xi for vi, xi in zip(v, x)) - c) % p:
continue
return list(x)
return None
from random import randint
p = 161435094849208186723743776068899835990543
n = 16
b = 255
v = [randint(0, p - 1) for _ in range(n)]
x = [randint(0, b) for _ in range(n)]
c = sum([vi * xi % p for vi, xi in zip(v, x)]) % p
print("# problem")
print(f"p = {p}")
print(f"n = {n}")
print(f"b = {b}")
print(f"v = {v}")
print(f"c = {c}")
print()
print("# solution")
print(f"x = {x}")
X = solve_centered(p, n, b, v, c)
print()
print("# found")
print(f"X = {X}")
print()
print("# success :)" if x == X else "# fail :(")