本文整理汇总了Python中BitVector.gf_multiply方法的典型用法代码示例。如果您正苦于以下问题:Python BitVector.gf_multiply方法的具体用法?Python BitVector.gf_multiply怎么用?Python BitVector.gf_multiply使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BitVector
的用法示例。
在下文中一共展示了BitVector.gf_multiply方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: encrypt
# 需要导入模块: import BitVector [as 别名]
# 或者: from BitVector import gf_multiply [as 别名]
def encrypt(self, plainText, isHex=0):
if isHex==0:
p=self.getRandomPrime()
q=self.getRandomPrime()
if not p==q: #if those two primes numbers are not the same
pm1=BitVector(intVal=int(p)-1, size=128)
qm1=BitVector(intVal=int(q)-1, size=128)
modulo_n=p.gf_multiply(q)# this is n
e=BitVector(intVal=17, size=128) #this is e
MI=e.multiplicative_inverse(pm1.gf_multiply(qm1))
d=BitVector(intVal=int(MI), size=256) # this is d
self.e=e
self.d=d
self.n=modulo_n
self.p=p
self.q=q
print "n:",int(self.n)
print "e:",int(self.e)
print "d:",int(self.d)
print "p:",int(self.p)
print "q:",int(self.q)
strr=RSA.getBitVectorFromText(plainText)#just getting BitVector from the text
print "plain text converted to int"
print int(strr)
C=pow(int(strr), int(e), int(modulo_n))
cipher=BitVector(intVal=C, size=256)
cipher= RSA.getTextFromBitVector(cipher)
return cipher
示例2: BitVector
# 需要导入模块: import BitVector [as 别名]
# 或者: from BitVector import gf_multiply [as 别名]
bv_modulus = BitVector(intVal=32)
print("modulus is bitvec: " + str(bv_modulus) +
" of int value: " + str(int(bv_modulus)))
bv = BitVector(intVal=17)
print("bv: " + str(bv) + " of int value: " + str(int(bv)))
result = bv.multiplicative_inverse(bv_modulus)
if result is not None:
print("MI bitvec is: " + str(result) +
" of int value: " + str(int(result)))
else:
print("No multiplicative inverse in this case")
# 17
print("\nTest multiplication in GF(2):")
a = BitVector(bitstring='0110001')
b = BitVector(bitstring='0110')
c = a.gf_multiply(b)
print("Product of a=" + str(a) + " b=" + str(b) + " is " + str(c))
# 00010100110
print("\nTest division in GF(2^n):")
mod = BitVector(bitstring='100011011') # AES modulus
n = 8
a = BitVector(bitstring='11100010110001')
quotient, remainder = a.gf_divide_by_modulus(mod, n)
print("Dividing a=" + str(a) + " by mod=" + str(mod) + " in GF(2^8) returns the quotient "
+ str(quotient) + " and the remainder " + str(remainder))
# 10001111
print("\nTest modular multiplication in GF(2^n):")
modulus = BitVector(bitstring='100011011') # AES modulus
n = 8
示例3: int
# 需要导入模块: import BitVector [as 别名]
# 或者: from BitVector import gf_multiply [as 别名]
n_found = 0
while n_found == 0:
if pcheck == 0:
pv = pv.gen_rand_bits_for_prime(128)
pcheck = pv.test_for_primality()
if qcheck == 0:
qv = qv.gen_rand_bits_for_prime(128)
qcheck = qv.test_for_primality()
if (pcheck != 0) and (qcheck != 0):
n = pv.gf_multiply(qv)
p = int(pv)
q = int(qv)
ptemp = BitVector(intVal=(p - 1), size=128)
qtemp = BitVector(intVal=(q - 1), size=128)
if int(ptemp.gcd(ev)) != 1 and int(qtemp.gcd(ev)) != 1:
pcheck = 0
qcheck = 0
n_found = 0
else:
n_found = 1