コード例 #1
0
    def setup(self):
        """
        Will choose a generator that will generates the *entire*
        multiplicative group modulo :param prime:
        """
        divisors = self.divisors(self._prime - 1)

        while True:
            root_test = 1
            random_number = self.process_number()

            sutil.debug("[i] Random number is: {}".format(random_number))
            sutil.debug("[i] Will check if number is primitive root !")

            for divisor in divisors:
                if sutil.primality_test(divisor):
                    root_test = pow(random_number, (self._prime - 1) / divisor,
                                    self._prime)
                else:
                    root_test = pow(random_number, divisor, self._prime)

                if root_test == 1:
                    sutil.debug("[x] Number is not generator !")
                    break

            if root_test != 1:
                sutil.debug("[o] Number is generator !")
                break

        return random_number
コード例 #2
0
    def __init__(self, prime=None, bites=GENERAL.PRIME_BITES, quick=False):
        """
        :param prime: prime number
        :type prime: Integer, Long or None
        :param int bites: number of bites for randome prime number generator
        :param bool quick: True for quick setup

        If :param args: is not set will be generare a prime number of
        :param bites: bites.
        """

        if not prime:
            if not isinstance(bites, int):
                raise TypeError("Parameter bites should be integer !")
            self._prime = self.get_prime(bites)

        else:
            if not sutil.primality_test(prime):
                raise ValueError("Parameter prime should be a prime number !")
            self._prime = prime

        sutil.debug("[i] Prime number is: {}".format(self._prime))

        if quick:
            self._primitive_root = self.quick_setup()
        else:
            self._primitive_root = self.setup()
コード例 #3
0
ファイル: protocol.py プロジェクト: c-square/homework
    def setup(self):
        """
        Will choose a generator that will generates the *entire*
        multiplicative group modulo :param prime:
        """
        divisors = self.divisors(self._prime - 1)

        while True:
            root_test = 1
            random_number = self.process_number()

            sutil.debug("[i] Random number is: {}".format(random_number))
            sutil.debug("[i] Will check if number is primitive root !")

            for divisor in divisors:
                if sutil.primality_test(divisor):
                    root_test = pow(random_number, (self._prime - 1) / divisor,
                                    self._prime)
                else:
                    root_test = pow(random_number, divisor, self._prime)

                if root_test == 1:
                    sutil.debug("[x] Number is not generator !")
                    break

            if root_test != 1:
                sutil.debug("[o] Number is generator !")
                break

        return random_number
コード例 #4
0
ファイル: protocol.py プロジェクト: c-square/homework
    def __init__(self, prime=None, bites=GENERAL.PRIME_BITES, quick=False):
        """
        :param prime: prime number
        :type prime: Integer, Long or None
        :param int bites: number of bites for randome prime number generator
        :param bool quick: True for quick setup

        If :param args: is not set will be generare a prime number of
        :param bites: bites.
        """

        if not prime:
            if not isinstance(bites, int):
                raise TypeError("Parameter bites should be integer !")
            self._prime = self.get_prime(bites)

        else:
            if not sutil.primality_test(prime):
                raise ValueError("Parameter prime should be a prime number !")
            self._prime = prime

        sutil.debug("[i] Prime number is: {}".format(self._prime))

        if quick:
            self._primitive_root = self.quick_setup()
        else:
            self._primitive_root = self.setup()
コード例 #5
0
    def divisors(number):
        """Compute the prime divisors for recived number"""
        divisors = []

        while number > 1:

            if sutil.primality_test(number):
                sutil.debug("[i] Last divisor: {}".format(number))
                divisors.append(number)
                break

            if GENERAL.DIVISORS == "brent_rho":
                divisor = sutil.brent_rho(number)
            elif GENERAL.DIVISORS == "pollard_rho":
                divisor = sutil.pollard_rho(number)
            else:
                raise ValueError("Invalid value for GENERAL.DIVISORS !")

            divisors.append(divisor)
            sutil.debug("[i] Divisor found: {}".format(divisor))
            number = number / divisor

        return divisors
コード例 #6
0
ファイル: protocol.py プロジェクト: c-square/homework
    def divisors(number):
        """Compute the prime divisors for recived number"""
        divisors = []

        while number > 1:

            if sutil.primality_test(number):
                sutil.debug("[i] Last divisor: {}".format(number))
                divisors.append(number)
                break

            if GENERAL.DIVISORS == "brent_rho":
                divisor = sutil.brent_rho(number)
            elif GENERAL.DIVISORS == "pollard_rho":
                divisor = sutil.pollard_rho(number)
            else:
                raise ValueError("Invalid value for GENERAL.DIVISORS !")

            divisors.append(divisor)
            sutil.debug("[i] Divisor found: {}".format(divisor))
            number = number / divisor

        return divisors