attack.py
def keygen_weak(self,
                    attack_param_w,
                    attack_param_la,
                    max_tries_for_A_gen=MAX_TRIES_FOR_A_GEN,
                    max_tries_for_V_gen=MAX_TRIES_FOR_V_GEN):
        """
        This function generates a random key pair for binary PKP that can be attacked with parameters
        (w, la) = (attack_param_w, attack_param_la). That is, it returns a triple (A, Vsec, Vpub) such
        that
            A is an m by n binary matrix
            V and Vsec are two n by l binary matrices
            A*Vsec = 0
            Vsec has no two equal rows (security requirement for PKP)
            Vpub is a permutation of Vsec
            The rowspace of A contains at least attack_param_la vectors of weight w

        Notice that we require that attack_param_la is limited <= m which is enough for the attack to
        work and it is much easier to generate.

        Args:
            attack_param_w (int): Attack parameter w
            attack_param_la (int): Attack parameter la
        """

        assert(attack_param_la <= self.m)

        for _try_A in range(max_tries_for_A_gen):

            A_low_weight_rows = [gen_binary_vector_of_fixed_weight(self.n, attack_param_w)
                                 for _ in range(attack_param_la)]
            A_random_rows = [random_vector(GF(2), self.n) for _ in range(attack_param_la, self.m)]


            A = matrix(GF(2), A_low_weight_rows + A_random_rows)

            if A.rank() < self.m:
                continue

            try:
                Vsec = self.gen_Vsec_from_A(A, max_tries_for_V_gen=max_tries_for_V_gen)
                Vpub = matrix(sorted(Vsec))

                return A, Vsec, Vpub

            except RuntimeError:
                pass

        raise ValueError('Could not generate a weak key with the selected parameters.')

        This function generates a random key pair for binary PKP that can be attacked with parameters
        (w, la) = (attack_param_w, attack_param_la). That is, it returns a triple (A, Vsec, Vpub) such
        that
            A is an m by n binary matrix
            V and Vsec are two n by l binary matrices
            A*Vsec = 0
            Vsec has no two equal rows (security requirement for PKP)
            Vpub is a permutation of Vsec
            The rowspace of A contains at least attack_param_la vectors of weight w

        Notice that we require that attack_param_la is limited <= m which is enough for the attack to
        work and it is much easier to generate.

        Args:
            attack_param_w (int): Attack parameter w
            attack_param_la (int): Attack parameter la
        
This function generates a random key pair for binary PKP that can be attacked with parameters
(w, la) = (attack_param_w, attack_param_la). That is, it returns a triple (A, Vsec, Vpub) such
that
A is an m by n binary matrix
V and Vsec are two n by l binary matrices
A*Vsec = 0
Vsec has no two equal rows (security requirement for PKP)
Vpub is a permutation of Vsec
The rowspace of A contains at least attack_param_la vectors of weight w

Notice that we require that attack_param_la is limited <= m which is enough for the attack to
work and it is much easier to generate.
This function generates a random key pair for binary PKP that can be attacked with parameters ( w la ) = ( attack_param_w attack_param_la ) . That is it returns a triple ( A Vsec Vpub ) such that A is an m by n binary matrix V and Vsec are two n by l binary matrices A * Vsec = 0 Vsec has no two equal rows ( security requirement for PKP ) Vpub is a permutation of Vsec The rowspace of A contains at least attack_param_la vectors of weight w Notice that we require that attack_param_la is limited < = m which is enough for the attack to work and it is much easier to generate .
def keygen_weak(self,
                    attack_param_w,
                    attack_param_la,
                    max_tries_for_A_gen=MAX_TRIES_FOR_A_GEN,
                    max_tries_for_V_gen=MAX_TRIES_FOR_V_GEN):
        assert(attack_param_la <= self.m)
        for _try_A in range(max_tries_for_A_gen):
            A_low_weight_rows = [gen_binary_vector_of_fixed_weight(self.n, attack_param_w)
                                 for _ in range(attack_param_la)]
            A_random_rows = [random_vector(GF(2), self.n) for _ in range(attack_param_la, self.m)]
            A = matrix(GF(2), A_low_weight_rows + A_random_rows)
            if A.rank() < self.m:
                continue
            try:
                Vsec = self.gen_Vsec_from_A(A, max_tries_for_V_gen=max_tries_for_V_gen)
                Vpub = matrix(sorted(Vsec))
                return A, Vsec, Vpub
            except RuntimeError:
                pass
        raise ValueError('Could not generate a weak key with the selected parameters.')
def keygen_weak ( self , attack_param_w , attack_param_la , max_tries_for_A_gen = MAX_TRIES_FOR_A_GEN , max_tries_for_V_gen = MAX_TRIES_FOR_V_GEN ) : assert ( attack_param_la <= self . m ) for _try_A in range ( max_tries_for_A_gen ) : A_low_weight_rows = [ gen_binary_vector_of_fixed_weight ( self . n , attack_param_w ) for _ in range ( attack_param_la ) ] A_random_rows = [ random_vector ( GF ( 2 ) , self . n ) for _ in range ( attack_param_la , self . m ) ] A = matrix ( GF ( 2 ) , A_low_weight_rows + A_random_rows ) if A . rank ( ) < self . m : continue try : Vsec = self . gen_Vsec_from_A ( A , max_tries_for_V_gen = max_tries_for_V_gen ) Vpub = matrix ( sorted ( Vsec ) ) return A , Vsec , Vpub except RuntimeError : pass raise ValueError ( 'Could not generate a weak key with the selected parameters.' )
This function generates a random key pair for binary PKP that can be attacked with parameters
(w, la) = (attack_param_w, attack_param_la).
This function generates a random key pair for binary PKP that can be attacked with parameters ( w la ) = ( attack_param_w attack_param_la ) .
"""
        This function generates a random key pair for binary PKP that can be attacked with parameters
        (w, la) = (attack_param_w, attack_param_la). That is, it returns a triple (A, Vsec, Vpub) such
        that
            A is an m by n binary matrix
            V and Vsec are two n by l binary matrices
            A*Vsec = 0
            Vsec has no two equal rows (security requirement for PKP)
            Vpub is a permutation of Vsec
            The rowspace of A contains at least attack_param_la vectors of weight w

        Notice that we require that attack_param_la is limited <= m which is enough for the attack to
        work and it is much easier to generate.

        Args:
            attack_param_w (int): Attack parameter w
            attack_param_la (int): Attack parameter la
        """
self
attack_param_w
Attack parameter w
Attack parameter w
attack_param_la
Attack parameter la
Attack parameter la
max_tries_for_A_gen
max_tries_for_V_gen