当前位置: 首页>>代码示例>>Python>>正文


Python random.randint方法代码示例

本文整理汇总了Python中Crypto.Random.random.randint方法的典型用法代码示例。如果您正苦于以下问题:Python random.randint方法的具体用法?Python random.randint怎么用?Python random.randint使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Crypto.Random.random的用法示例。


在下文中一共展示了random.randint方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: rsa_d

# 需要导入模块: from Crypto.Random import random [as 别名]
# 或者: from Crypto.Random.random import randint [as 别名]
def rsa_d(rsa, d):
  """
  Factor RSA Public Key using Private Exponent.
  Args:
    rsa : instance of RSA
    d   : Private Exponent
  Return:
    p   : Prime 1 (bigger than `q`)
    q   : Prime 2 (smaller than `p`)
  """
  k = rsa.e * d - 1
  g = 0
  x = 0
  while True:
    g = random.randint(2, rsa.n - 1)
    t = k
    while t % 2 == 0:
      t = t // 2
      x = pow(g, t, rsa.n)
      y = gcd(x - 1, rsa.n)
      if x > 1 and y > 1:
        p = y
        q = rsa.n // y
        return (max(p, q), min(p, q)) 
开发者ID:scryptos,项目名称:scryptoslib,代码行数:26,代码来源:RSA.py

示例2: __init__

# 需要导入模块: from Crypto.Random import random [as 别名]
# 或者: from Crypto.Random.random import randint [as 别名]
def __init__(self, group=14, randInt=randint):
        self.group = group

        # I could use nested try statements
        # or I could use isinstance with if-elif-else
        # I chose the latter, if you disagree, submit an issue
        if isinstance(group, int):
            self.g = groups[group][0]
            self.p = groups[group][1]

        elif isinstance(group, (list,tuple)):
            self.g = group[0]
            self.p = group[1]

        elif isinstance(group, dict):
            self.g = group['g']
            self.p = group['p']

        else:
            raise TypeError("{} is not an int, list, tuple, or dict"
            .format(group))

        self.a = randInt(1, self.p - 1)
        self.public = pow(self.g, self.a, self.p)  # g**a % p
        self.key = 0 
开发者ID:deadPix3l,项目名称:pyDHE,代码行数:27,代码来源:__init__.py

示例3: _generate_key

# 需要导入模块: from Crypto.Random import random [as 别名]
# 或者: from Crypto.Random.random import randint [as 别名]
def _generate_key():
	"""
	Generate private-public key pair.
	For security reasons, either p should be a safe prime or g should have a
	prime subgroup order. Otherwise it is vulnerable to Short Subgroup Attack.

	:Parameters: _None_

	:Variables:
		g : int/long
			Base point for modular exponentiation.
		p : int/long
			Modulus for modular exponentiation. Should be a safe prime.
		x : int/long
			Receiver's private key, should be kept secret.
		h : int/long
			Receiver's public key
		q : int/long
			Order of group generated by p and equals p-1

	:Return: A tuple containing a Public Key object (class `PublicKey`) and
	a Private Key object (class `PrivateKey`)
	"""
	# Assigning the largest 1024-bit safe prime as p
	p = (1 << 1024) - 1093337
	x = randint(2, p-2)
	g = 7
	q = p - 1
	h = pow(g, x, p)
	pubkey = PublicKey(h, p, g, q)
	privkey = PrivateKey(x, p, g, q)
	return (pubkey, privkey) 
开发者ID:ashutosh1206,项目名称:Crypton,代码行数:34,代码来源:example.py

示例4: _encrypt

# 需要导入模块: from Crypto.Random import random [as 别名]
# 或者: from Crypto.Random.random import randint [as 别名]
def _encrypt(message, pubkey):
	"""
	Encrypt message using ElGamal encryption system

	:Parameters:
		message : str
				  plaintext to be encrypted
		pubkey  : instance of `PublicKey` class
				  Alice's public key parameters used for encryption

	:Variables:
		g : int/long
			Base point for modular exponentiation.
		p : int/long
			Modulus for modular exponentiation. Should be a safe prime.
		h : int/long
			Receiver's public key
		q : int/long
			Order of group generated by p and equals p-1
		y : int/long
			Ephemeral key generated by the sender
		c1, c2: int/long
			Ciphertext pair
		s : int/long
			Shared secret

	:Return:
		A tuple containing ciphertext pair c1, c2
	"""
	h = pubkey.h
	p = pubkey.p
	g = pubkey.g
	q = pubkey.q
	m = bytes_to_long(message)
	# Generating ephemeral key: `y`
	y = randint(2, p-2)
	c1 = pow(g, y, p)
	# Computing the shared secret: `s`
	s = pow(h, y, p)
	c2 = (m*s) % p
	return (c1, c2) 
开发者ID:ashutosh1206,项目名称:Crypton,代码行数:43,代码来源:example.py

示例5: randomInt

# 需要导入模块: from Crypto.Random import random [as 别名]
# 或者: from Crypto.Random.random import randint [as 别名]
def randomInt(minimum, maximum):
	""" Returns a random integer between or equald to minimum and maximum
	"""
	if minimum < 0: minimum = 0
	if maximum < 0: maximum = 100
	return random.randint(minimum, maximum)

#------------------------------------------------------------------------ 
开发者ID:Arno0x,项目名称:WSC2,代码行数:10,代码来源:helpers.py

示例6: transaction_id

# 需要导入模块: from Crypto.Random import random [as 别名]
# 或者: from Crypto.Random.random import randint [as 别名]
def transaction_id(self):
        """
        Transaction ID for Transbank, a secure random int between 0 and 999999999.
        """
        if not self._transaction_id:
            self._transaction_id = random.randint(0, 10000000000 - 1)
        return self._transaction_id 
开发者ID:pedroburon,项目名称:tbk,代码行数:9,代码来源:payment.py


注:本文中的Crypto.Random.random.randint方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。