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


Python BitVector.get_bitvector_in_hex方法代码示例

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


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

示例1: decryption

# 需要导入模块: import BitVector [as 别名]
# 或者: from BitVector import get_bitvector_in_hex [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_hex [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: print

# 需要导入模块: import BitVector [as 别名]
# 或者: from BitVector import get_bitvector_in_hex [as 别名]
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: ")
print(myhexstring)                                    # 68656c6c6f

print("\nConstructing a bit vector from the uppercase hexstring '68656C6C6F':")
bv4 = BitVector(hexstring="68656C6C6F")
print(bv4)
myhexstring = bv4.get_bitvector_in_hex()
print("Hex string recovered from the previous bitvector: ")
print(myhexstring)                                    # 68656c6c6f

print(
    "\nDemonstrating the raw bytes mode of constructing a bit vector (useful for reading public and private keys):")
mypubkey = 'ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA5amriY96HQS8Y/nKc8zu3zOylvpOn3vzMmWwrtyDy+aBvns4UC1RXoaD9rDKqNNMCBAQwWDsYwCAFsrBzbxRQONHePX8lRWgM87MseWGlu6WPzWGiJMclTAO9CTknplG9wlNzLQBj3dP1M895iLF6jvJ7GR+V3CRU6UUbMmRvgPcsfv6ec9RRPm/B8ftUuQICL0jt4tKdPG45PBJUylHs71FuE9FJNp01hrj1EMFObNTcsy9zuis0YPyzArTYSOUsGglleExAQYi7iLh17pAa+y6fZrGLsptgqryuftN9Q4NqPuTiFjlqRowCDU7sSxKDgU7bzhshyVx3+pzXO4D2Q== [email protected]'
import base64
if sys.version_info[0] == 3:
开发者ID:gsnedders,项目名称:BitVector,代码行数:33,代码来源:BitVectorDemo.py


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