本文整理汇总了Python中bitstring.BitArray.append方法的典型用法代码示例。如果您正苦于以下问题:Python BitArray.append方法的具体用法?Python BitArray.append怎么用?Python BitArray.append使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bitstring.BitArray
的用法示例。
在下文中一共展示了BitArray.append方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: render
# 需要导入模块: from bitstring import BitArray [as 别名]
# 或者: from bitstring.BitArray import append [as 别名]
def render(self, ctx=None):
'''
:param ctx: rendering context in which the method was called
:rtype: `Bits`
:return: rendered value of the container
'''
self._initialize()
if ctx is None:
ctx = RenderContext()
ctx.push(self)
self.set_offset(self._offset, ctx)
if self.is_default():
self._current_rendered = self._default_rendered
ctx.pop()
return self._default_rendered
rendered = BitArray()
offset = 0
for field in self._fields:
frendered = field.render(ctx)
if not isinstance(frendered, Bits):
raise KittyException('the field %s:%s was rendered to type %s, you should probably wrap it with appropriate encoder' % (
field.get_name(), type(field), type(frendered)))
rendered.append(frendered)
offset += len(frendered)
self.set_current_value(rendered)
ctx.pop()
return self._current_rendered
示例2: pointer_to_binary
# 需要导入模块: from bitstring import BitArray [as 别名]
# 或者: from bitstring.BitArray import append [as 别名]
def pointer_to_binary (self, pointer, configuration, thread = None):
"""Convert a Pointer object to the binary init load value for a Programmed Offset entry."""
# Add the Default Offset for each thread, so we point to the correct per-thread instance of the pointed-to variable
# None thread means a shared variable holds the init data, or other unique location identical to all threads.
if thread is not None:
default_offset = configuration.default_offset.offsets[thread]
else:
default_offset = 0
# Addresses wrap around when the offset is added,
# so express negative values as the modular sum value
# Read and write pointers have different address ranges and offset bit widths
if "D" in pointer.memory:
# write pointer
offset = (pointer.base + pointer.offset - pointer.address + default_offset) % configuration.memory_depth_words_write
offset = BitArray(uint=offset, length=configuration.po_write_offset_bit_width)
else:
# read pointer
offset = (pointer.base + pointer.offset - pointer.address + default_offset) % configuration.memory_depth_words
offset = BitArray(uint=offset, length=configuration.po_read_offset_bit_width)
# The increment is a signed magnitude number (absolute value and sign bit)
increment = BitArray(uint=abs(pointer.incr), length=configuration.po_increment_bits)
increment_sign = self.to_sign_bit(pointer.incr)
increment_sign = BitArray(uint=increment_sign, length=configuration.po_increment_sign_bits)
# Now pack them into the Programmed Offset entry binary configurations
pointer_bits = BitArray()
for entry in [increment_sign, increment, offset]:
pointer_bits.append(entry)
return pointer_bits
示例3: main
# 需要导入模块: from bitstring import BitArray [as 别名]
# 或者: from bitstring.BitArray import append [as 别名]
def main():
"""
1. Get file.
2. Convert from base64 to hex string representation.
3. Convert hex string representation to BitArray.
4. Feed into Repeating_XOR_Breaker
"""
cipher_source = "https://cryptopals.com/static/challenge-data/6.txt"
cipher_reader = Data_reader(cipher_source)
data = cipher_reader.get_data()
data = ''.join(data)
converted = Base64_To_Hex(data).convert()
data_to_break = BitArray(hex=converted)
breaker = Repeating_XOR_Breaker(data_to_break)
candidate_keys = breaker.solve()
print "Candidate Keys:", candidate_keys
for key_set in candidate_keys:
whole_key = BitArray(hex='0x00')
for key in key_set:
whole_key.append(BitArray(int=key, length=8))
print "whole_key:", whole_key
decrypter = ExtendedKeyDecrypter()
decrypter.set_decrypt_key(whole_key.hex)
print decrypter.decrypt()
示例4: get_word
# 需要导入模块: from bitstring import BitArray [as 别名]
# 或者: from bitstring.BitArray import append [as 别名]
def get_word(self, allow_recalc=False):
word = BitArray(0)
for i in range(5):
b = self.buf.popleft()
if b >> 6 != 1:
pass
#print("6-of-8 decode wrong")
#raise RTCMBitError()
b = BitArray(uint=(b&0x3f), length=6)
b.reverse()
word.append(b)
if self.p30:
word ^= BitArray(uint=0x3fffffc0, length=30)
print(hex(word.uint))
if allow_recalc and self.calculate_parity(word) != word.uint & 0x3f:
self.p29 = 1
if self.calculate_parity(word) != word.uint & 0x3f:
raise RTCMParityError()
self.p30 = word.uint & 1
self.p29 = (word.uint & 2) >> 1
return word
示例5: p_expression_concat
# 需要导入模块: from bitstring import BitArray [as 别名]
# 或者: from bitstring.BitArray import append [as 别名]
def p_expression_concat(p):
"expression : expression CONCAT expression"
s1=BitArray(p[1])
s2=BitArray(p[3])
# print str(s2)
s1.append('0b' + s2.bin)
p[0] = '0b' + s1.bin
示例6: team
# 需要导入模块: from bitstring import BitArray [as 别名]
# 或者: from bitstring.BitArray import append [as 别名]
def team(self):
c = BitArray()
c.append("uint:8=%s" % self.player_slot)
if c[0] == 0:
return "radiant"
else:
return "dire"
示例7: branch
# 需要导入模块: from bitstring import BitArray [as 别名]
# 或者: from bitstring.BitArray import append [as 别名]
def branch(self, origin, origin_enable, destination, predict_taken, predict_enable, condition_name):
condition_bits = self.conditions[condition_name]
origin_bits = BitArray(uint=origin, length=Branch.origin_width)
destination_bits = BitArray(uint=destination, length=Branch.destination_width)
config = BitArray()
for entry in [origin_bits, origin_enable, destination_bits, predict_taken, predict_enable, condition_bits]:
config.append(entry)
return config
示例8: decrypt
# 需要导入模块: from bitstring import BitArray [as 别名]
# 或者: from bitstring.BitArray import append [as 别名]
def decrypt(self):
result = BitArray(hex='0x00')
skip_by = self.key_len
for i in xrange(0, self.cipher_stream.len, skip_by):
xor_res = self.cipher_stream[i:skip_by] ^ self.XOR_to_use
result.append(xor_res)
skip_by += self.key_len
return result
示例9: testCreationFromOct
# 需要导入模块: from bitstring import BitArray [as 别名]
# 或者: from bitstring.BitArray import append [as 别名]
def testCreationFromOct(self):
s = BitArray(oct="7")
self.assertEqual(s.oct, "7")
self.assertEqual(s.bin, "111")
s.append("0o1")
self.assertEqual(s.bin, "111001")
s.oct = "12345670"
self.assertEqual(s.length, 24)
self.assertEqual(s.bin, "001010011100101110111000")
s = BitArray("0o123")
self.assertEqual(s.oct, "123")
示例10: generateConfirmationKey
# 需要导入模块: from bitstring import BitArray [as 别名]
# 或者: from bitstring.BitArray import append [as 别名]
def generateConfirmationKey(identitySecret,time,tag=""):
identitysecret = b64decode(identitySecret)
secret = BitArray(bytes=identitysecret,length=len(identitysecret)*8)
if tag != "":
tagBuff = BitArray(bytes=tag,length=len(tag)*8)
buff = BitArray(4*8)
time = int(time)
buff.append(BitArray(int=time,length=32))
if tag != "":
buff.append(tagBuff)
conf_hmac = hmac.new(secret.tobytes(),buff.tobytes(),hashlib.sha1)
return b64encode(conf_hmac.digest())
示例11: bitPackDPCMModel
# 需要导入模块: from bitstring import BitArray [as 别名]
# 或者: from bitstring.BitArray import append [as 别名]
def bitPackDPCMModel(order,predictor,nCodeWords,codebook,sigLen,encodedx):
a=BitArray(uint=order, length=8)
b=BitArray().join(BitArray(float=x, length=32) for x in predictor.params)
a.append(b)
a.append(BitArray(uint=int(nCodeWords), length=8))
b=BitArray().join(BitArray(float=x, length=32) for x in codebook)
a.append(b)
a.append(BitArray(uint=int(sigLen), length=32))
nBits=int(np.ceil(np.log2(nCodeWords)));
b=BitArray().join(BitArray(uint=x, length=nBits) for x in encodedx)
a.append(b)
return(a)
示例12: createZVector
# 需要导入模块: from bitstring import BitArray [as 别名]
# 或者: from bitstring.BitArray import append [as 别名]
def createZVector(self,aListOfGfuncionXorCwList):
tempZ_Vector = BitArray()
tempResultPerSection = BitArray(int = 0,length = (int)(math.sqrt(self.DB_LENGTH)))
aListOfGfuncionXorCwList.reverse()
while aListOfGfuncionXorCwList:
tempResultPerSection = BitArray(int = 0,length = (int)(math.sqrt(self.DB_LENGTH)))
for _ in range(0,self.seedsPerSection):
tempResultPerSection = tempResultPerSection ^ aListOfGfuncionXorCwList.pop()
tempZ_Vector.append(tempResultPerSection)
return tempZ_Vector
示例13: condition_to_binary
# 需要导入模块: from bitstring import BitArray [as 别名]
# 或者: from bitstring.BitArray import append [as 别名]
def condition_to_binary (self, bdo, branch):
condition = branch.condition
dyadic = bdo.dyadic
condition_bits = BitArray()
for entry in [condition.a, condition.b, condition.ab_operator]:
field_bits = getattr(dyadic, entry, None)
field_bits = getattr(bdo, entry, field_bits)
if field_bits is None:
print("Unknown branch field value: {0}".format(entry))
self.ask_for_debugger()
condition_bits.append(field_bits)
return condition_bits
示例14: encode_header
# 需要导入模块: from bitstring import BitArray [as 别名]
# 或者: from bitstring.BitArray import append [as 别名]
def encode_header(self, res):
res.append(pack('uint:8', self.d['layout_version']))
res.append(pack('uint:8', self.d['eeprom_size']))
res.append(pack('uint:8', 0)) # Used EEPROM size
uid = BitArray()
uid.append(pack('uint:8', self.d['bus_protocol_version']))
uid.append(pack('uintbe:16', self.d['model']))
uid.append(pack('uint:8', self.d['hardware_revision']))
uid.append(pack('uintbe:24', self.d['serial']))
# Calculate CRC over unique id
uid.append(pack('uint:8', unique_id_crc(uid.bytes)))
res.append(uid)
res.append(pack('uint:8', self.d['firmware_version']))
res.append_string(self.d['name'])
示例15: __init__
# 需要导入模块: from bitstring import BitArray [as 别名]
# 或者: from bitstring.BitArray import append [as 别名]
class Bmc:
"""
Bmc Biphase Mark Coding
Generate biphase mark coding streams
"""
def __init__(self):
self.__lastState = False
self.__data = BitArray()
def add(self,datastream):
"""
Add datastream
"""
for b in datastream:
if self.__lastState:
if b:
self.__data.append('0b00')
self.__lastState = False
else:
self.__data.append('0b01')
else:
if b:
self.__data.append('0b11')
self.__lastState = True
else:
self.__data.append('0b10')
def get(self):
"""
Return modulated datastream
"""
return self.__data