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


Python BitVector.get_bitvector_in_ascii方法代码示例

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


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

示例1: decryption

# 需要导入模块: import BitVector [as 别名]
# 或者: from BitVector import get_bitvector_in_ascii [as 别名]
def decryption(message):
	cypher = BitVector(textstring = message)
	stateMatrix = cypher[:128]
	plaintext = BitVector(size=0)

	block_count = 0	
	num_of_blocks =len(cypher)/128
	##loop until the message is all 0s
	for blockNum in range(num_of_blocks):
		block_count = block_count+1
		i=num_of_rounds-1

		stateMatrix = addRoundKey(i,stateMatrix)

		i=i-1
		while(i>=0):
			stateMatrix = invShiftRows(stateMatrix)
			
			stateMatrix = invSubBytes(stateMatrix)

			stateMatrix = addRoundKey(i, stateMatrix)

			if(i!=0):
				stateMatrix = invMixCollumns(stateMatrix)
			i=i-1

		plaintext = plaintext+stateMatrix
		if(blockNum != (num_of_blocks-1)):
			cypher = cypher[128:]
			stateMatrix = cypher[:128]
	if(len(sys.argv)==4):
		print "Block count",block_count
		print plaintext.get_bitvector_in_hex()
	ascii = plaintext.get_bitvector_in_ascii()
	return ascii[:len(ascii)-4]
开发者ID:Twistedchurro,项目名称:AESpy,代码行数:37,代码来源:client.py

示例2: encryption

# 需要导入模块: import BitVector [as 别名]
# 或者: from BitVector import get_bitvector_in_ascii [as 别名]
def encryption(message):
		
	plaintext = BitVector(textstring = message)
	if((len(plaintext)%128)!=0):
		padlen = 128 - (len(plaintext)%128)
		for _ in range(padlen/8):
			padding = BitVector(intVal=(padlen/8), size=8)
			plaintext = plaintext + padding
		#print "Padding",plaintext.get_bitvector_in_hex()
	stateMatrix = plaintext[:128]
	cypher = BitVector(size=0)
	block_count = 0
	num_of_blocks =len(plaintext)/128
	##loop until the message is all 0s 
	for blockNum in range(num_of_blocks):
		block_count = block_count+1
		stateMatrix = addRoundKey(0,stateMatrix)
		i=1

		while(i<num_of_rounds):
			print "Encryption Block:", block_count,". Round:",i			

			stateMatrix = subBytes(stateMatrix)
			print "Enc: after subBytes",stateMatrix.get_bitvector_in_hex()

			stateMatrix = shiftRows(stateMatrix)
			print "Enc: after shiftRows",stateMatrix.get_bitvector_in_hex()

			if(i!=num_of_rounds-1):
				stateMatrix = mixCollumns(stateMatrix)
				print "Enc: after mixCollumns",stateMatrix.get_bitvector_in_hex()

			stateMatrix = addRoundKey(i, stateMatrix)
			print "Enc: after addRC:",i,stateMatrix.get_bitvector_in_hex()

			i=i+1

		cypher = cypher+stateMatrix

		if(blockNum != (num_of_blocks-1)):
			plaintext = plaintext[128:]
			stateMatrix = plaintext[:128]
	if(len(sys.argv)==3):
		print "Block count",block_count
		print cypher.get_bitvector_in_hex()
	return cypher.get_bitvector_in_ascii()
开发者ID:Twistedchurro,项目名称:AESpy,代码行数:48,代码来源:client_DEBUG_ROUNDS.py

示例3: BitVector

# 需要导入模块: import BitVector [as 别名]
# 或者: from BitVector import get_bitvector_in_ascii [as 别名]
# Construct a bit vector directly from a bit string:
bv = BitVector(bitstring='00110011')
print("\nBit Vector constructed directly from a bit string:")
print(bv)                                    # 00110011

bv = BitVector(bitstring='')
print("\nBit Vector constructed directly from an empty bit string:")
print(bv)                                    # nothing
print("\nInteger value of the previous bit vector:")
print(bv.int_val())                         # 0

print("\nConstructing a bit vector from the textstring 'hello':")
bv3 = BitVector(textstring="hello")
print(bv3)
mytext = bv3.get_bitvector_in_ascii()
print("Text recovered from the previous bitvector: ")
print(mytext)                                         # hello
print("\nConstructing a bit vector from the textstring 'hello\\njello':")
bv3 = BitVector(textstring="hello\njello")
print(bv3)
mytext = bv3.get_bitvector_in_ascii()
print("Text recovered from the previous bitvector:")
print(mytext)                                         # hello
# jello

print("\nConstructing a bit vector from the hexstring '68656c6c6f':")
bv4 = BitVector(hexstring="68656c6c6f")
print(bv4)
myhexstring = bv4.get_bitvector_in_hex()
print("Hex string recovered from the previous bitvector: ")
开发者ID:gsnedders,项目名称:BitVector,代码行数:32,代码来源:BitVectorDemo.py


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