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


Python BitVector.getTextFromBitVector方法代码示例

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


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

示例1: decrypt

# 需要导入模块: import BitVector [as 别名]
# 或者: from BitVector import getTextFromBitVector [as 别名]
def decrypt(key_list):
    fout = open(fout2, 'wb+')
    bv = BitVector( filename = fout1 )
    subbyte = decryptable
    while (bv.more_to_read):
        bitvec = bv.read_bits_from_file( 128 )
        if len(bitvec) != 128:
            bitvec.pad_from_right(128 - len(bitvec))
        if len(bitvec) == 128:
            bitvec = bitvec ^ key_list[14]
            for i in range(14):
                #shift row
                for m in range(3):
                    for fan in range(m+1):
                        temp = BitVector( bitstring=str(bitvec[(32*3 + 8*(m+1)):(32*3+(8*(m+2)))]) )
                        for j in range(3):
                            j = 3 - j
                            bitvec[(32*j+8*(m+1)):(32*j+8*(m+2))] = bitvec[(32*(j-1)+8*(m+1)):(32*(j-1)+8*(m+2))] 
                        bitvec[(8*(m+1)):(8*(m+2))] = temp
                #look up the table
                for j in range(16):
                    #print subbyte[int(bitvec[8*j:(8*j + 4)])][int(bitvec[(8*j + 4):(8*j + 8)])]
                    bitvec[8*j:(8*j+8)] = subbyte[int(bitvec[8*j:(8*j + 4)])][int(bitvec[(8*j + 4):(8*j + 8)])]
                #add with round key
                bitvec = bitvec ^ key_list[13 - i]
                #mix columns
                if i != 13:
                    tempout = BitVector(size=128)
                    for k in range(4):
                        for j in range(4):
                            tempbyte = BitVector( size=8 )
                            for l in range(4):
                                tempmultiply2 = bitvec[(32*j+l*8):(32*j+(l+1)*8)] 
                                tempmultiply1 = BitVector( intVal= colmixD[k][l], size=8)
                                tempbyte = tempbyte ^ (tempmultiply1.gf_multiply_modular(tempmultiply2, modulus, 8))                
                                tempout[(32*j+8*k):(32*j+8*(k+1))] = BitVector(bitstring=str(tempbyte))
                    bitvec = BitVector(bitstring=str(tempout))
        fout.write(bitvec.getTextFromBitVector())
    fout.close()
开发者ID:kibazhang,项目名称:Computer_and_Network_Security,代码行数:41,代码来源:AES_Encryption.py

示例2: getOutput_encrypt

# 需要导入模块: import BitVector [as 别名]
# 或者: from BitVector import getTextFromBitVector [as 别名]
def getOutput_encrypt(fileout, outputlist):
    fout = open(fileout, 'wb')
    for item in outputlist:
        temp = BitVector(intVal=item, size=256)
        fout.write(temp.getTextFromBitVector())
    fout.close()
开发者ID:kibazhang,项目名称:Computer_and_Network_Security,代码行数:8,代码来源:RSA_Public_Key_Algorithm.py

示例3: BitVector

# 需要导入模块: import BitVector [as 别名]
# 或者: from BitVector import getTextFromBitVector [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.intValue())                         # 0

print("\nConstructing a bit vector from the textstring 'hello':")
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
开发者ID:jain98,项目名称:PurdueProgramming,代码行数:32,代码来源:BitVectorDemo.py

示例4: BitVector

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

    # Create a bitvector for storing the output plaintext bit array:
    msg_decrypted_bv = BitVector( size = 0 )                    #(T)

    # Carry out differential XORing of bit blocks and decryption:
    previous_decrypted_block = bv_iv                            #(U)
    for i in range(0, len(encrypted_bv) / BLOCKSIZE):           #(V)
        bv = encrypted_bv[i*BLOCKSIZE:(i+1)*BLOCKSIZE]          #(W)
        temp = bv.deep_copy()                                   #(X)
        bv ^=  previous_decrypted_block                         #(Y)
        previous_decrypted_block = temp                         #(Z)
        bv ^=  key_bv                                           #(a)
        msg_decrypted_bv += bv                                  #(b)

    outputtext = msg_decrypted_bv.getTextFromBitVector()        #(c)
    if marktwain.search(outputtext):
        # Generate the ASCII version of Key
        ascii_key = binascii.unhexlify('%x' % key_bv.intValue()) 
	print "**** WOO HOO ****"
        print "Bit Key      : ", str(key_bv)
        print "Key in ASCII : ", ascii_key
	print "Text: \n", outputtext
	break

###### MODIFICATIONS END #########

# Write the plaintext to the output file:
FILEOUT = open(sys.argv[2], 'w')                                #(d)
FILEOUT.write(outputtext)                                       #(e)
FILEOUT.close()                                                 #(f)
开发者ID:sransara,项目名称:rocket-science,代码行数:33,代码来源:cryptBreak.py


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