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


Python BitVector.gf_multiply方法代码示例

本文整理汇总了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
开发者ID:CrocKim,项目名称:Introduction-to-Computer-Security-ECE404,代码行数:30,代码来源:ece404_hw7_Sungsoo.py

示例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
开发者ID:gsnedders,项目名称:BitVector,代码行数:33,代码来源:BitVectorDemo.py

示例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
开发者ID:nkumar212,项目名称:ECE404,代码行数:31,代码来源:rand_n_gen.py


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