本文整理汇总了Python中BitVector.pad_from_right方法的典型用法代码示例。如果您正苦于以下问题:Python BitVector.pad_from_right方法的具体用法?Python BitVector.pad_from_right怎么用?Python BitVector.pad_from_right使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BitVector
的用法示例。
在下文中一共展示了BitVector.pad_from_right方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: runTripleDes
# 需要导入模块: import BitVector [as 别名]
# 或者: from BitVector import pad_from_right [as 别名]
def runTripleDes():
sxy_list = open(sys.argv[6],'r').read().split('\n')
Sx = BitVector(hexstring=sxy_list[0].lower())
Sy = BitVector(hexstring=sxy_list[1].lower())
if len(Sx) != 164 or len(Sy) != 164:
raise ValueError("Keys are not the correct size.")
key_64_list = seperateKeys(Sx, Sy)
if sys.argv[2] == '-t':
file_bv = BitVector(textstring=open(sys.argv[1],'r').read())
elif sys.argv[2] == '-h':
file_bv = BitVector(hexstring=open(sys.argv[1],'r').read())
else:
raise Exception
if sys.argv[5] == '-e' and len(file_bv)%64 != 0:
file_bv.pad_from_right(64-(len(file_bv) % 64))
result = tripleDES(file_bv, key_64_list, sys.argv[5])
if sys.argv[5] == '-d':
i = len(result) - 8
while i > 0:
if int(result[i::]) != 0:
break
i -= 8
i += 8
result = result[0:i]
if sys.argv[5] == '-e':
print("\n\nOUTPUT (ciphertext):\n\n")
else:
print("\n\nOUTPUT (decrypted):\n\n")
print (hexdump(result.get_text_from_bitvector()))
if sys.argv[4] == '-t':
open(sys.argv[3],'w').write(result.get_text_from_bitvector())
elif sys.argv[4] == '-h':
open(sys.argv[3],'w').write(result.get_hex_string_from_bitvector())
else:
raise Exception
if len(sys.argv) == 9:
if sys.argv[8] == '-t':
verilog_output = BitVector(textstring=open(sys.argv[7],'r').read())
elif sys.argv[8] == '-h':
verilog_output = BitVector(hexstring=open(sys.argv[7],'r').read())
if verilog_output.get_hex_string_from_bitvector() != result.get_hex_string_from_bitvector():
raise ValueError("Output does not match python!")
print ("\n")
示例2: print
# 需要导入模块: import BitVector [as 别名]
# 或者: from BitVector import pad_from_right [as 别名]
print("\nTest forming a [5:22] slice of the above bit vector:")
bv4 = bv3[5:22]
print(bv4) # 00100100000011010
print("\nTest the iterator:")
for bit in bv4:
print(bit) # 0 0 1 0 0 1 0 0 0 0 0 0 1 1 0 1 0
print("\nDemonstrate padding a bit vector from left:")
bv = BitVector(bitstring='101010')
bv.pad_from_left(4)
print(bv) # 0000101010
print("\nDemonstrate padding a bit vector from right:")
bv.pad_from_right(4)
print(bv) # 00001010100000
print("\nTest the syntax 'if bit_vector_1 in bit_vector_2' syntax:")
try:
bv1 = BitVector(bitstring='0011001100')
bv2 = BitVector(bitstring='110011')
if bv2 in bv1:
print("%s is in %s" % (bv2, bv1))
else:
print("%s is not in %s" % (bv2, bv1))
except ValueError as arg:
print("Error Message: " + str(arg))
print(
"\nTest the size modifier when a bit vector is initialized with the intVal method:")