本文整理汇总了Python中BitVector.getHexStringFromBitVector方法的典型用法代码示例。如果您正苦于以下问题:Python BitVector.getHexStringFromBitVector方法的具体用法?Python BitVector.getHexStringFromBitVector怎么用?Python BitVector.getHexStringFromBitVector使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BitVector
的用法示例。
在下文中一共展示了BitVector.getHexStringFromBitVector方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: HashbyGhost
# 需要导入模块: import BitVector [as 别名]
# 或者: from BitVector import getHexStringFromBitVector [as 别名]
def HashbyGhost():
dirScan = glob('input/*.*')
fileCount = 0
while(fileCount < len(dirScan)):
bv = BitVector(filename = dirScan[fileCount])
myHash = BitVector(size = 32)
while (bv.more_to_read):
bv1 = bv.read_bits_from_file(8)
myHash[0:8] = bv1 ^ myHash[0:8]
myHash << 8
bv.close_file_object()
myHexHash = myHash.getHexStringFromBitVector()
dumpFile = open('output/output.txt', 'a')
dumpFile.write('\n')
dumpFile.write(dirScan[fileCount])
dumpFile.write(":")
dumpFile.write(myHexHash)
dumpFile.close()
fileCount += 1
示例2: BitVector
# 需要导入模块: import BitVector [as 别名]
# 或者: from BitVector import getHexStringFromBitVector [as 别名]
bv3 = BitVector(textstring = "hello")
print(bv3)
mytext = bv3.getTextFromBitVector()
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_text_from_bitvector()
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.getHexStringFromBitVector()
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:
import binascii
keydata = base64.b64decode(bytes(mypubkey.split(None)[1], 'utf-8'))
else:
keydata = base64.b64decode(mypubkey.split(None)[1])
bv = BitVector( rawbytes = keydata )
print(bv)
# Test array-like indexing for a bit vector:
示例3: open
# 需要导入模块: import BitVector [as 别名]
# 或者: from BitVector import getHexStringFromBitVector [as 别名]
from BitVector import *
import hashlib
K = [0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2]
fi = open("sha.txt","w")
chunk = BitVector(textstring = "hello".encode())
size = BitVector(intVal = len(chunk),size = 64)
chunk = chunk + BitVector(intVal = 1,size = 1)
while(len(chunk) < 448):
chunk = chunk + BitVector(intVal = 0,size = 1)
chunk = chunk + size
fi.write("Chunk: " + chunk.getHexStringFromBitVector() + '\n')
fi.write("MSA\n")
w = [0] * 64
w[0:16] = [chunk[x:x+32] for x in range(0, 512, 32)]
for i in range(16,64):
s0 = (w[i-15].deep_copy() >> 7) ^ (w[i-15].deep_copy() >> 18) ^ (w[i-15].deep_copy().shift_right(3))
s1 = (w[i-2].deep_copy() >> 17) ^ (w[i-2].deep_copy() >> 19) ^ (w[i-2].deep_copy().shift_right(10))
w[i] = BitVector(intVal = ((int(w[i-16]) + int(s0) + int(w[i-7]) + int(s1)) % (2**32)),size = 32)
fi.write("w[" + str(i) + "]: " + w[i].getHexStringFromBitVector())
a = BitVector(hexstring = '6a09e667')
b = BitVector(hexstring = 'bb67ae85')
c = BitVector(hexstring = '3c6ef372')
d = BitVector(hexstring = 'a54ff53a')
e = BitVector(hexstring = '510e527f')
f = BitVector(hexstring = '9b05688c')
g = BitVector(hexstring = '1f83d9ab')
h = BitVector(hexstring = '5be0cd19')
fi.write('Comp\n')
for i in range(64):
ch = (e & f) ^ (~e & g)
maj = (a & b) ^ (a & c) ^ (b & c)