SharedConcatenation_DIFG.sagewsOpen in CoCalc
Deep-iterates-based attack on the Concatenation combiner of $k$ hash functions
n = var('n')
l = var('l')
k = var('k')
kappa = var('kappa')
g2 = var('g2')
g1 = var('g1')

restriction_g1 = (g1 >= n/2, g1 >= n - l)

Phase1  = l
Phase2 = g1 - l + k*n - k * g1
Phase3_1 = g2
Phase3_2 = k*n - (k + 1) * (n - g1) + n - g2

show('--------------------------------------------------------------------')
show('Complexity of Phases are (log2): ')
show('Phase 1: ', Phase1)
show('Phase 2: ', Phase2)
show('Phase 3 term 1: ', Phase3_1.simplify_full())
show('Phase 3 term 2: ', Phase3_2.simplify_full())
show('--------------------------------------------------------------------')

g2s = solve([Phase3_1 == Phase3_2], g2)[0]
show('--------------------------------------------------------------------')
show('Balance the first two terms in Phase 3 by setting: ')
show(g2s)
g2s = g2s.rhs()

Phase3_1  = Phase3_1(g2 = g2s)
Phase3_2 = Phase3_2(g2 = g2s)

show('--------------------------------------------------------------------')
show('Complexity of Phases becomes (log2): ')
show('Phase2: ', Phase2)
show('Phase 3 term 1: ', Phase3_1.simplify_full())
show('Phase 3 term 2:', Phase3_2.simplify_full())

g1s = solve([Phase2 == Phase3_1], g1)[0]
show('--------------------------------------------------------------------')
show('Balance Phase 2 and Phase 3 term 1 by setting:')
show(g1s)
g1s = g1s.rhs()
show('This balance only valid under the restriction: ')
show(restriction_g1)
show('Which implies: ')
bound_l = solve([g1s >= n - l, g1s >= n/2, l < n], l)[-1]
bound_l_ = (bound_l[0], bound_l[1])
show(bound_l_)
show('--------------------------------------------------------------------')

Phase1_case1 = Phase1(g1 = g1s)
Phase2_case1 = Phase2(g1 = g1s)
Phase3_1_case1 = Phase3_1(g1 = g1s)
Phase3_2_case1 = Phase3_2(g1 = g1s)

show('--------------------------------------------------------------------')
show('For the case')
show(bound_l_)
show('Complexity of Phases are (log2): ')
show('Phase 1: ', Phase1_case1.simplify_full())
show('Phase 2: ', Phase2_case1.simplify_full())
show('Phase 3 term 1: ', Phase3_1_case1.simplify_full())
show('Phase 3 term 2: ', Phase3_2_case1.simplify_full())
show('--------------------------------------------------------------------')

ls = solve([Phase1_case1 == Phase2_case1], l)[0]
Phase1_case1 = Phase1_case1 (l = ls.rhs())
Phase2_case1 = Phase2_case1 (l = ls.rhs())
Phase3_1_case1 = Phase3_1_case1 (l = ls.rhs())
Phase3_2_case1 = Phase3_2_case1 (l = ls.rhs())

show('--------------------------------------------------------------------')
show('The optimal complexity is (log2):')
show('Phase1: ', Phase1_case1.simplify_full())
show('Phase2: ', Phase2_case1.simplify_full())
show('Phase 3, term 1:', Phase3_1_case1.simplify_full())
show('Phase 3, term 2:', Phase3_2_case1.simplify_full())
show('Obtained for ')
show(ls)
show('--------------------------------------------------------------------')

for i in range(2, 4):
show(' ------------------------------ ', k == i, ' ------------------------------')
Phase1cplx = Phase1_case1(k = i)
Phase1cplxs = Phase1cplx(kappa=log(i, 2)).simplify_full()
Phase2cplx = Phase2_case1(k = i)
Phase2cplxs = Phase2cplx(kappa=log(i, 2)).simplify_full()
Phase3_1cplx = Phase3_1_case1(k = i)
Phase3_1cplxs = Phase3_1cplx(kappa=log(i, 2)).simplify_full()
Phase3_2cplx = Phase3_2_case1(k = i)
Phase3_2cplxs = Phase3_2cplx(kappa=log(i, 2)).simplify_full()
show('Phase 1: ', Phase2cplxs)
show('Phase 2: ', Phase2cplxs)
show('Phase 3 term 1: ', Phase3_1cplxs)
show('Phase 3 term 2: ', Phase3_2cplxs)

--------------------------------------------------------------------
Complexity of Phases are (log2):
Phase 1: $\displaystyle l$
Phase 2: $\displaystyle -g_{1} k + k n + g_{1} - l$
Phase 3 term 1: $\displaystyle g_{2}$
Phase 3 term 2: $\displaystyle g_{1} k + g_{1} - g_{2}$
--------------------------------------------------------------------
--------------------------------------------------------------------
Balance the first two terms in Phase 3 by setting:
$\displaystyle g_{2} = \frac{1}{2} \, g_{1} k + \frac{1}{2} \, g_{1}$
--------------------------------------------------------------------
Complexity of Phases becomes (log2):
Phase2: $\displaystyle -g_{1} k + k n + g_{1} - l$
Phase 3 term 1: $\displaystyle \frac{1}{2} \, g_{1} k + \frac{1}{2} \, g_{1}$
Phase 3 term 2: $\displaystyle \frac{1}{2} \, g_{1} k + \frac{1}{2} \, g_{1}$
--------------------------------------------------------------------
Balance Phase 2 and Phase 3 term 1 by setting:
$\displaystyle g_{1} = \frac{2 \, {\left(k n - l\right)}}{3 \, k - 1}$
This balance only valid under the restriction:
($\displaystyle g_{1} \geq \frac{1}{2} \, n$, $\displaystyle g_{1} \geq -l + n$)
Which implies:
($\displaystyle \frac{1}{3} \, n < l$, $\displaystyle l < n$)
--------------------------------------------------------------------
--------------------------------------------------------------------
For the case
($\displaystyle \frac{1}{3} \, n < l$, $\displaystyle l < n$)
Complexity of Phases are (log2):
Phase 1: $\displaystyle l$
Phase 2: $\displaystyle -\frac{{\left(k + 1\right)} l - {\left(k^{2} + k\right)} n}{3 \, k - 1}$
Phase 3 term 1: $\displaystyle -\frac{{\left(k + 1\right)} l - {\left(k^{2} + k\right)} n}{3 \, k - 1}$
Phase 3 term 2: $\displaystyle -\frac{{\left(k + 1\right)} l - {\left(k^{2} + k\right)} n}{3 \, k - 1}$
--------------------------------------------------------------------
--------------------------------------------------------------------
The optimal complexity is (log2):
Phase1: $\displaystyle \frac{1}{4} \, {\left(k + 1\right)} n$
Phase2: $\displaystyle \frac{1}{4} \, {\left(k + 1\right)} n$
Phase 3, term 1: $\displaystyle \frac{1}{4} \, {\left(k + 1\right)} n$
Phase 3, term 2: $\displaystyle \frac{1}{4} \, {\left(k + 1\right)} n$
Obtained for
$\displaystyle l = \frac{1}{4} \, {\left(k + 1\right)} n$
--------------------------------------------------------------------
------------------------------ $\displaystyle k = 2$ ------------------------------
Phase 1: $\displaystyle \frac{3}{4} \, n$
Phase 2: $\displaystyle \frac{3}{4} \, n$
Phase 3 term 1: $\displaystyle \frac{3}{4} \, n$
Phase 3 term 2: $\displaystyle \frac{3}{4} \, n$
------------------------------ $\displaystyle k = 3$ ------------------------------
Phase 1: $\displaystyle n$
Phase 2: $\displaystyle n$
Phase 3 term 1: $\displaystyle n$
Phase 3 term 2: $\displaystyle n$