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


Python BitVector.deep_copy方法代码示例

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


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

示例1: build_s_box

# 需要导入模块: import BitVector [as 别名]
# 或者: from BitVector import deep_copy [as 别名]
def build_s_box(encrypt_or_decrypt):
	AES_modulus = BitVector(bitstring='100011011')
	c = BitVector(bitstring='01100011')
	d = BitVector(bitstring='00000101')

	new_sub_bytes = []
	if (encrypt_or_decrypt == 'e'):
		for i in range(0, 256):
			# Build lookup table
			a = BitVector(intVal = i, size=8).gf_MI(AES_modulus, 8) if i != 0 else BitVector(intVal=0)
			# Byte scrambling
			a1,a2,a3,a4 = [a.deep_copy() for x in range(4)]
			a ^= (a1 >> 4) ^ (a2 >> 5) ^ (a3 >> 6) ^ (a4 >> 7) ^ c
			new_sub_bytes.append(int(a))
	else:
		for i in range(0, 256):
			b = BitVector(intVal = i, size=8)
			# byte scrambling
			b1,b2,b3 = [b.deep_copy() for x in range(3)]
			b = (b1 >> 2) ^ (b2 >> 5) ^ (b3 >> 7) ^ d
			check = b.gf_MI(AES_modulus, 8)
			b = check if isinstance(check, BitVector) else 0
			new_sub_bytes.append(int(b))

	sub_byte_table = []
	for i in range(16):
		sub_byte_table.append([])
		for j in range(16):
			sub_byte_table[i].append(new_sub_bytes[(i * 16) + j])

	return sub_byte_table
开发者ID:michael-pr,项目名称:Security,代码行数:33,代码来源:aes.py

示例2: get_c_byte_step

# 需要导入模块: import BitVector [as 别名]
# 或者: from BitVector import deep_copy [as 别名]
def get_c_byte_step( byte, encrypt ) : 
    byte = byte.reverse()

    if(encrypt) :
        c_d_byte = BitVector( bitstring = '11000110' )
        xor_base = BitVector( bitstring = '10001111' )
    else :
        c_d_byte = BitVector( bitstring = '10100000' )
        xor_base = BitVector( bitstring = '00100101' )

    newByte = BitVector( bitstring = '00000000' )
    
    
    xor_lists = [xor_base.deep_copy() >> x for x in range(8)]

    
    for i, xor_list in enumerate(xor_lists) :
        temp = xor_list & byte
        newBit = get_xor_of_single_bv(temp)
        newBit = newBit ^ c_d_byte[i]

        newByte[i] = newBit

    newByte = newByte.reverse()

    return newByte
开发者ID:sheel7,项目名称:ECE404,代码行数:28,代码来源:ece404_hw04_sheeley.py

示例3: GenerateSubTable

# 需要导入模块: import BitVector [as 别名]
# 或者: from BitVector import deep_copy [as 别名]
def GenerateSubTable(modeChar):
	#Table Generation Variables
	modulus_poly = BitVector(bitstring = '100011011') #irreducible polynomial used in AES --> (x^8 + x^4 + x^3 + x + 1)
	byte_c = BitVector(bitstring = '01100011') #Encryption Mangle-Byte
	byte_d = BitVector(bitstring = '00000101') #Decryption Mangle-Byte
	scrambledBV = BitVector(size = 8)
	#Initialize 16x16 Sub-Table with all 0 Bit-Vectors
	zeroBV = BitVector(size = 8)
	LookUpTable = [[zeroBV.deep_copy() for x in range(16)] for y in range(16)] 
	#Set Each Table Entry to Multiplicative Inverse (in GF(2^8)) of Bit-Vector Concatenation of Row and Column 4-bit Bit-Vectors
	for x in range(16):
		for y in range(16):
			rowBV = BitVector(intVal=x, size=4) #Creat Bit Vector for Row Value
			colBV = BitVector(intVal=y, size=4) #Creat Bit Vector for Column Value
			tableBV_entry = rowBV + colBV
			#Perform MI & Bit-Mangling on Table Entries
			#If Mode is Encryption...
			if modeChar == 'E':
				#Only find MI of all bit-vectors except 0
				if (x != 0) or (y != 0):
					tableBV_entry = tableBV_entry.gf_MI(modulus_poly, 8) #Determine MI of table entry Bit-Vector
				for bit_ind in range(0, 8):
					newBit = tableBV_entry[bit_ind]^tableBV_entry[(bit_ind+1)%8]^tableBV_entry[(bit_ind+2)%8]^tableBV_entry[(bit_ind+3)%8]^tableBV_entry[(bit_ind+4)%8]^byte_c[bit_ind]
					scrambledBV[bit_ind] = newBit
			#If Mode is Decryption...
			else:
				for bit_ind in range(0, 8):
					newBit = tableBV_entry[(bit_ind+6)%8]^tableBV_entry[(bit_ind+3)%8]^tableBV_entry[(bit_ind+1)%8]^byte_d[bit_ind]
					scrambledBV[bit_ind] = newBit
				#Only find MI of all bit-vectors except 0
				if int(scrambledBV) != 0:
					scrambledBV = scrambledBV.gf_MI(modulus_poly, 8) #Determine MI of table entry Bit-Vector
			LookUpTable[x][y] = copy.deepcopy(scrambledBV)
	return LookUpTable
开发者ID:timtrippel,项目名称:Encryption-Tools,代码行数:36,代码来源:ttrippel_AES.py

示例4: genTables

# 需要导入模块: import BitVector [as 别名]
# 或者: from BitVector import deep_copy [as 别名]
def genTables():
    c = BitVector(bitstring='01100011')
    d = BitVector(bitstring='00000101')
    for i in range(0, 256):
        a = BitVector(intVal = i, size=8).gf_MI(AES_modulus,8) if i != 0 else BitVector(intVal=0)

        a1,a2,a3,a4 = [a.deep_copy() for x in range(4)]
        a ^= (a1 >> 4) ^ (a2 >> 5) ^ (a3 >> 6) ^ (a4 >> 7) ^ c
        subBytesTable.append(int(a))

        b = BitVector(intVal = i, size=8)

        b1,b2,b3 = [b.deep_copy() for x in range(3)]
        b = (b1 >> 2) ^ (b2 >> 5) ^ (b3 >> 7) ^ d
        check = b.gf_MI(AES_modulus, 8)
        b = check if isinstance(check, BitVector) else 0
        invSubBytesTable.append(int(b))
开发者ID:ajdunker,项目名称:ECE404,代码行数:19,代码来源:ece404_hw04_dunker.py

示例5: genTables

# 需要导入模块: import BitVector [as 别名]
# 或者: from BitVector import deep_copy [as 别名]
def genTables():
    c = BitVector(bitstring="01100011")
    d = BitVector(bitstring="00000101")
    for i in range(0, 256):
        # For the encryption SBox
        a = BitVector(intVal=i, size=8).gf_MI(AES_modulus, 8) if i != 0 else BitVector(intVal=0)
        # For byte scrambling for the encryption SBox entries:
        a1, a2, a3, a4 = [a.deep_copy() for x in range(4)]
        a ^= (a1 >> 4) ^ (a2 >> 5) ^ (a3 >> 6) ^ (a4 >> 7) ^ c
        subBytesTable.append(int(a))
        # For the decryption Sbox:
        b = BitVector(intVal=i, size=8)
        # For byte scrambling for the decryption SBox entries:
        b1, b2, b3 = [b.deep_copy() for x in range(3)]
        b = (b1 >> 2) ^ (b2 >> 5) ^ (b3 >> 7) ^ d
        check = b.gf_MI(AES_modulus, 8)
        b = check if isinstance(check, BitVector) else 0
        invSubBytesTable.append(int(b))
开发者ID:mbaio94,项目名称:ECE404_Assignments,代码行数:20,代码来源:gen_tables.py

示例6: GenerateRoundKeys

# 需要导入模块: import BitVector [as 别名]
# 或者: from BitVector import deep_copy [as 别名]
def GenerateRoundKeys(Encryption_Key, KeyPermutation1_List, KeyPermutation2_List, ShiftInfoDict):
	#Generate 56-Bit BV from Encryption Key
	encryptionKeyBV = BitVector(textstring = Encryption_Key) #Declare BitVector from bit string

	#Perform Permutation 1
	textBV = encryptionKeyBV.deep_copy()
	for ind in range(0,56):
		textBV[ind] = encryptionKeyBV[KeyPermutation1_List[ind]]

	encryptionKeyBV = encryptionKeyBV.permute(KeyPermutation1_List)

	#Split Key into two 28-Bit Halves
	[key1_L, key1_R] = encryptionKeyBV.divide_into_two() #Split key into two 28-bit halves

	#Perform Round 1 Shift for Encryption 
	round1_shift = ShiftInfoDict[1] #obtain number of bits to shift key in round 1
	key1_L = key1_L << round1_shift #circularly shift left, left half of key
	key1_R = key1_R << round1_shift #circularly shift left, right half of key

	#Perform Contraction Permutation for round 1 key
	round1_key = key1_L + key1_R #join together both left and right halves of round 1 key
	round1_key = round1_key.permute(KeyPermutation2_List) #perform 56 to 48 bit contracting permutation

	#Add 1st Round Key to List
	roundNum = 1
	keyList = [round1_key]
	key_L = key1_L
	key_R = key1_R

	#Add Remaining Round Keys to List
	for roundNum in range(1,16):
		round_shift = ShiftInfoDict[roundNum+1] #obtain number of bits to shift ket by in present round
		key_L = key_L.deep_copy() << round_shift #circularly shift left, left half of key
		key_R = key_R.deep_copy() << round_shift #circularly shift left, right half of key
		round_key = key_L.deep_copy() + key_R.deep_copy() #join together both left and right halves of round 1 key
		round_key = round_key.permute(KeyPermutation2_List)#perform 56 to 48 bit contracting permutation
		keyList.append(round_key.deep_copy())

	return keyList
开发者ID:timtrippel,项目名称:Encryption-Tools,代码行数:41,代码来源:DES_ttrippel.py

示例7: Encrypt_64Bit_Block

# 需要导入模块: import BitVector [as 别名]
# 或者: from BitVector import deep_copy [as 别名]
def Encrypt_64Bit_Block(lBV, rBV, round_key, SBoxes_Dict_List, PBox_List):
	#Perform Expansion Permutation	
	sliceList = []; #empty list to hold 4-bit slices of right half of bit block
	bv_index = 0

	#Copy Right Side Bit Block
	rbv_copy = rBV.deep_copy()

	#Break 32-bit right half into 4-bit blocks
	for bv_index in range(0,29,4):
		sliceList.append(rBV[bv_index:(bv_index + 4)])

	#Expand 4-bit BV to a 6-bit BV
	#Create List of 8, 6-Bit, Bit Vectors
	newBV = BitVector(size = 6)
	newBV_List = []
	for ind in range(0, 8):
		newBV_List.append(newBV.deep_copy())
	#Update 6-Bit Long Bit Vectors with correct values
	for bv_index in range(0, 8):
		for ind in range(0, 6):
			if (ind == 0):
				newBV_List[bv_index][ind] = sliceList[bv_index - 1][3]
			elif (ind == 5):
				if ((bv_index + 1) < 8):
					newBV_List[bv_index][ind] = sliceList[bv_index + 1][0]
				else:
					newBV_List[bv_index][ind] = sliceList[0][0]
			else:
				newBV_List[bv_index][ind] = sliceList[bv_index][ind-1]

	#Concatenate all 6-bit BVs into one 48-bit block
	expandedBitBlock_bv = newBV_List[0]
	for bv_index in range(1,8):
		expandedBitBlock_bv = expandedBitBlock_bv + newBV_List[bv_index]

	#Perform Round-Key XOR-ing
	expandedBitBlock_bv = expandedBitBlock_bv ^ round_key;

	#Perform Substitution with S-Boxes
	#Split expanded 48-bit block back to 6-bit blocks
	SBox_SliceList = []
	for bv_index in range(0,43,6):
		SBox_SliceList.append(expandedBitBlock_bv[bv_index:(bv_index + 6)])
	#Perform S-Box Substitution
	subNumberList = []
	for bv_index in range(0,8):
		rowBitString = str(SBox_SliceList[bv_index][0]) #splice off 1st bit of 6-bit block
		rowBitString = rowBitString + str(SBox_SliceList[bv_index][5]) #splice off 1st bit of 6-bit block
		rowBV = BitVector(bitstring = rowBitString)
		columnBV = SBox_SliceList[bv_index][1:5] #splice off center 4 bits of 6-bit block
		rowIndex = int(rowBV) #retrieve row index number
		colIndex = int(columnBV) #retrieve column index number
		subNumberList.append(copy.deepcopy('{0:04b}'.format(SBoxes_Dict_List[bv_index][rowIndex][colIndex])))
		subNumberBitString = ''.join(subNumberList)
	subNumber_BV = BitVector(bitstring = subNumberBitString)

	#Perform Permutation with P-Box
	subNumber_BV = subNumber_BV.permute(PBox_List)

	#Perform XOR-ing with Left 32-Bit Half
	newR_bv = subNumber_BV ^ lBV
	newL_bv = rbv_copy

	#Return New Left and Right Bit Vectors
	return newL_bv, newR_bv
开发者ID:timtrippel,项目名称:Encryption-Tools,代码行数:68,代码来源:DES_ttrippel.py

示例8: PadMessage

# 需要导入模块: import BitVector [as 别名]
# 或者: from BitVector import deep_copy [as 别名]
#Perform Message Padding
message_bv, inputString = PadMessage(inputFileName, inputFile_bv)

#Perform 80-Round Processing
words = [None] * 80
for n in range(0, message_bv.length(), 1024):
	#Create Word Schedule
	block_bv = message_bv[n:n+1024]
	words[0:16] = [block_bv[ind:ind+64] for ind in range(0,1024, 64)]
	for ind in range(16, 80):
		sigma_0 = (words[ind - 15].deep_copy() >> 1) ^ (words[ind - 15].deep_copy() >> 8) ^ ((words[ind - 15].deep_copy()).shift_right(7))
		sigma_1 = (words[ind - 2].deep_copy() >> 19) ^ (words[ind - 2].deep_copy() >> 61) ^ ((words[ind - 2].deep_copy()).shift_right(6))
		words[ind] = BitVector(intVal=((int(words[ind-16]) + int(sigma_0) + int(words[ind-7]) + int(sigma_1)) % (2**64)), size=64)
	#Perform Round Functions
	a, b, c, d, e, f, g, h = hb0.deep_copy(), hb1.deep_copy(), hb2.deep_copy(), hb3.deep_copy(), hb4.deep_copy(), hb5.deep_copy(), hb6.deep_copy(), hb7.deep_copy()
	for ind in range(80):
		#Round Calculations
		sigma_a = (a.deep_copy() >> 28) ^ (a.deep_copy() >> 34) ^ (a.deep_copy() >> 39)
		sigma_e = (e.deep_copy() >> 14) ^ (e.deep_copy() >> 18) ^ (e.deep_copy() >> 41)
		ch = (e & f) ^ (~e & g)
		maj = (a & b) ^ (a & c) ^ (b & c)
		T_1 = (int(h) + int(ch) + int(sigma_e) + int(words[ind]) + int(k[ind])) % (2**64)
		T_2 = (int(sigma_a) + int(maj)) % (2**64)
		h = g
		g = f
		f = e
		e = BitVector(intVal=((int(d) + T_1) % (2**64)), size=64)
		d = c
		c = b
		b = a
开发者ID:timtrippel,项目名称:Encryption-Tools,代码行数:32,代码来源:SHA512.py

示例9: __init__

# 需要导入模块: import BitVector [as 别名]
# 或者: from BitVector import deep_copy [as 别名]

#.........这里部分代码省略.........
        self.prev_e = BitVector(hexstring="510e527fade682d1")
        self.prev_f = BitVector(hexstring="9b05688c2b3e6c1f")
        self.prev_g = BitVector(hexstring="1f83d9abfb41bd6b")
        self.prev_h = BitVector(hexstring="5be0cd19137e2179")

    #################################################################
    #############  f Process function as in notes  ##################
    #################################################################
    def _f(self, block):

        # Initialize the 80 words
        words = [None] * 80

        # Set the first 16 words based on the 1024 bit input
        words[0:16] = [block[x:x+64] for x in range(0, 1024, 64)]

        # Generate the remaining words
        for i in range(16, 80) :
            words[i] = self._get_next_word(words[i-16], words[i-15],
                                           words[i-7], words[i-2])

        mod = 2 ** 64

        #Process block for 80 rounds
        for i in range(80):

            T1 = (int(self.h) + self._Ch()) % mod
            T1 = (T1 + self._sige()) % mod
            T1 = (T1 + int(words[i])) % mod
            T1 = (T1 + int(self.K[i],16)) % mod

            T2 = (self._siga() + self._Maj()) % mod

            self.h = self.g.deep_copy()
            self.g = self.f.deep_copy()
            self.f = self.e.deep_copy()
            new_e_int = (int(self.d) + T1) % mod
            self.e = BitVector(intVal=new_e_int, size=64)
            self.d = self.c.deep_copy()
            self.c = self.b.deep_copy()
            self.b = self.a.deep_copy()
            new_a_int = (T1 + T2) % mod
            self.a = BitVector(intVal=new_a_int, size=64)

        # Add the previous register to the new one
        a_int = (int(self.prev_a) + int(self.a)) % mod
        b_int = (int(self.prev_b) + int(self.b)) % mod
        c_int = (int(self.prev_c) + int(self.c)) % mod
        d_int = (int(self.prev_d) + int(self.d)) % mod
        e_int = (int(self.prev_e) + int(self.e)) % mod
        f_int = (int(self.prev_f) + int(self.f)) % mod
        g_int = (int(self.prev_g) + int(self.g)) % mod
        h_int = (int(self.prev_h) + int(self.h)) % mod

        # Set the registers for the next block
        self.prev_a = BitVector(intVal=a_int, size=64)
        self.a = self.prev_a.deep_copy()

        self.prev_b = BitVector(intVal=b_int, size=64)
        self.b = self.prev_b.deep_copy()

        self.prev_c = BitVector(intVal=c_int, size=64)
        self.c = self.prev_c.deep_copy()

        self.prev_d = BitVector(intVal=d_int, size=64)
        self.d = self.prev_d.deep_copy()
开发者ID:sheel7,项目名称:ECE404,代码行数:70,代码来源:hw07.py

示例10: BitVector

# 需要导入模块: import BitVector [as 别名]
# 或者: from BitVector import deep_copy [as 别名]
    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)
    S0 = (a.deep_copy() >> 2) ^ (a.deep_copy() >> 13) ^ (a.deep_copy() >> 22)
    e_copy = e.deep_copy()
    S1 = (e.deep_copy() >> 6) ^ (e.deep_copy() >> 11) ^ (e.deep_copy() >> 25)
    T_1 = (int(h) + int(S1) + int(ch) + int(K[i]) + int(w[i])) % 2**32
    T_2 = (int(S0) + int(maj)) % 2**32
    h = g
    g = f
    f = e
    e = BitVector(intVal = (int(d) + int(T_1)) % (2**32), size = 32)
    d = c
    c = b
    b = a
    a = BitVector(intVal = ((int(T_1) + int(T_2)) % (2**32)), size = 32)
    fi.write('a(' + str(i) + '): ' + a.getHexStringFromBitVector() + '\n')
h0 = BitVector(intVal = ((int( BitVector(hexstring = '6a09e667')) + int(a)) % 2**32), size = 32)
h1 = BitVector(intVal = ((int( BitVector(hexstring = 'bb67ae85')) + int(b)) % 2**32), size = 32) 
开发者ID:andresavilas,项目名称:ECE337Project,代码行数:33,代码来源:shascript.py


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