本文整理汇总了Python中BitVector.gf_divide方法的典型用法代码示例。如果您正苦于以下问题:Python BitVector.gf_divide方法的具体用法?Python BitVector.gf_divide怎么用?Python BitVector.gf_divide使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BitVector
的用法示例。
在下文中一共展示了BitVector.gf_divide方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: BitVector
# 需要导入模块: import BitVector [as 别名]
# 或者: from BitVector import gf_divide [as 别名]
a = BitVector( bitstring='00000010' )
#b = BitVector( bitstring='0110' )
b = BitVector( bitstring='000001111' )
c = a.gf_multiply(b)
print("Product of a=" + str(a) + " b=" + str(b) + " is " + str(c))
# 10100110
#sys.exit(0)
print("\nTest division in GF(2^n):")
mod = BitVector( bitstring='100011011' ) # AES modulus
n = 8
a = BitVector( bitstring='11100010110001' )
quotient, remainder = a.gf_divide(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))
print("\nTest modular multiplication in GF(2^n):")
modulus = BitVector( bitstring='100011011' ) # AES modulus
n = 8
a = BitVector( bitstring='0110001' )
b = BitVector( bitstring='0110' )
c = a.gf_multiply_modular(b, modulus, n)
print("Modular product of a=" + str(a) + " b=" + str(b) + " in GF(2^8) is " + str(c))
print("\nTest multiplicative inverses in GF(2^3) with " + \
"modulus polynomial = x^3 + x + 1:")
print("Find multiplicative inverse of a single bit array")
modulus = BitVector( bitstring='100011011' ) # AES modulus
n = 8