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


Python BitVector.get_hex_string_from_bitvector方法代码示例

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


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

示例1: gen_w4

# 需要导入模块: import BitVector [as 别名]
# 或者: from BitVector import get_hex_string_from_bitvector [as 别名]
def gen_w4(w3,ri):
    w3r = w3 << 8
    print ("w"+str((ri-1)*4+3)+" after one byte circular rotation")
    print (w3r.get_hex_string_from_bitvector())
    k_subbytes = BitVector(size = 0)
    for i in range(4):
        row = w3r[i*8:i*8+4].int_val()
        print (row),
        col = w3r[i*8+4:i*8+8].int_val()
        print (col),

        k_sub = BitVector(intVal = sbox[16*row+col], size = 8)
        print(k_sub),
        print(k_sub.get_hex_string_from_bitvector())
        k_subbytes += k_sub

    print ("k_subbytes")
    print (k_subbytes),
    print (k_subbytes.get_hex_string_from_bitvector())
    rcbv = BitVector(intVal = Rcon[ri], size = 32)
    print (rcbv)
    kg = k_subbytes ^ rcbv
    print ("kg")
    print (kg),
    print (kg.get_hex_string_from_bitvector())
    return kg
开发者ID:yinuoli1114,项目名称:0409_ComputerAndNetwork_Security_YinuoLi,代码行数:28,代码来源:aes_yinuo.py

示例2: RSA_decrypt

# 需要导入模块: import BitVector [as 别名]
# 或者: from BitVector import get_hex_string_from_bitvector [as 别名]
def RSA_decrypt(cipherfile, private_key, p, q):
    print ("Decrypt bagin#######################################")
    f = open(cipherfile,'r')
    hexstr = f.read()
    print (hexstr)
    m = 0
    n = 64
    strlis = []
    while(n <= len(hexstr)):
        strlis.append(hexstr[m:n])
        m += 64
        n += 64
    plains_bv = BitVector(size=0)
    for substr in strlis:
        package = BitVector(hexstring = substr)
        print ("package")
        print (package.get_hex_string_from_bitvector())

        package_int = package.int_val()

        Vp = pow(package_int,private_key[0],p)
        Vq = pow(package_int,private_key[0],q)
        pbv = BitVector(intVal=p)
        qbv = BitVector(intVal=q)
        Xp = q * qbv.multiplicative_inverse(pbv).int_val()
        Xq = p * pbv.multiplicative_inverse(qbv).int_val()
        plain_int = (Vp*Xp + Vq*Xq) % private_key[1]

        plain_bv = BitVector(intVal=plain_int,size=128)
        print ("plain_bv")
        print (plain_bv.get_hex_string_from_bitvector())
        plains_bv += plain_bv
    fo = open("decrypted.txt",'w')
    plains_bv.write_to_file(fo)
开发者ID:yinuoli1114,项目名称:0409_ComputerAndNetwork_Security_YinuoLi,代码行数:36,代码来源:Li_RSA_hw06.py

示例3: aesDecryption

# 需要导入模块: import BitVector [as 别名]
# 或者: from BitVector import get_hex_string_from_bitvector [as 别名]
def aesDecryption(cipherfile,roundkeys,np):
    print ("Decryption begin %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
    f = open(cipherfile,'r')
    hexstr = f.read()
    print (hexstr)

    m = 0
    n = 32
    strlis = []
    while(n <= len(hexstr)):
        strlis.append(hexstr[m:n])
        m += 32
        n += 32
    packages = BitVector(size=0)
    print ("substr AAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAa")
    print (strlis)
    for substr in strlis:
        package = BitVector(hexstring=substr)
        print (package.get_hex_string_from_bitvector())
        last4w = BitVector(size = 0)
        for j in range(len(roundkeys[10])):
            last4w += roundkeys[10][j]
        print ("last4w")
        print (last4w.get_hex_string_from_bitvector())
        packager = package ^ last4w
        print ("packager")
        print (packager.get_hex_string_from_bitvector())
        for ri in range(9,-1,-1):
            print (str(ri)+" Decrypt round$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$")
            shiftrows = inv_shift_rows(packager)
            subinv = inv_sub_bytes(shiftrows)
            print ("subinv")
            print (subinv.get_hex_string_from_bitvector())
            ad_rk = add_round_key(subinv,roundkeys,ri)
            print ("ad_rk")
            print (ad_rk.get_hex_string_from_bitvector())
            if ri > 0:
                colum_inv = inv_mix_columns(ad_rk)
            else:
                colum_inv = ad_rk
            packager = colum_inv
            print ("packager")
            print (packager.get_hex_string_from_bitvector())
        packages += packager
    for i in range(9,0,-1):
        print (i)
    print ("np")
    print (np)
    if np > 0:
        packages = packages.__getslice__(0,(len(strlis)-1)*128+np)
    print (packages.get_hex_string_from_bitvector())
    outfile = "decryptedtext.txt"
    fo = open(outfile,'w')
    packages.write_to_file(fo)
    hh = "abcdefghijklmn"
    print (hh)
    rr = hh[0:5]
    print (rr)
开发者ID:yinuoli1114,项目名称:0409_ComputerAndNetwork_Security_YinuoLi,代码行数:60,代码来源:aes_yinuo.py

示例4: inv_shift_rows

# 需要导入模块: import BitVector [as 别名]
# 或者: from BitVector import get_hex_string_from_bitvector [as 别名]
def inv_shift_rows(packager):
    print ("shift_rows begin###############")
    print (packager.get_hex_string_from_bitvector())
    state_array = []
    for i in range(4):
        row_array = BitVector(size=0)
        for j in range(4):
            temp = packager[(32*j+8*i):(32*j+8*i+8)]
            row_array += temp
        state_array.append(row_array)
    print ("state_array")
    for i in range(len(state_array)):
        print (state_array[i].get_hex_string_from_bitvector())
    state_array[1] >> 8
    state_array[2] >> 16
    state_array[3] >> 24

    print ("state_array after")
    for i in range(len(state_array)):
        print (state_array[i].get_hex_string_from_bitvector())
    shiftbv = BitVector(size=0)
    for j in range(4):
        for i in range(4):
            shiftbv += state_array[i][j*8:j*8+8]
    print ("shiftbv")
    print (shiftbv.get_hex_string_from_bitvector())
    return shiftbv
开发者ID:yinuoli1114,项目名称:0409_ComputerAndNetwork_Security_YinuoLi,代码行数:29,代码来源:aes_yinuo.py

示例5: sub_bytes

# 需要导入模块: import BitVector [as 别名]
# 或者: from BitVector import get_hex_string_from_bitvector [as 别名]
def sub_bytes(block):
    subbytes = BitVector(size=0)
    for i in range(16):
        print (i),
        row = block[i*8:i*8+4].int_val()
        print (row),
        col = block[i*8+4:i*8+8].int_val()
        print (col),
        sub = BitVector(intVal = sbox[16*row+col], size = 8)
        print (sub),
        print(sub.get_hex_string_from_bitvector())
        subbytes += sub
    #print ("subbytes")
    #print (subbytes)
    print (subbytes.get_hex_string_from_bitvector())
    return subbytes
开发者ID:yinuoli1114,项目名称:0409_ComputerAndNetwork_Security_YinuoLi,代码行数:18,代码来源:aes_yinuo.py

示例6: runTripleDes

# 需要导入模块: import BitVector [as 别名]
# 或者: from BitVector import get_hex_string_from_bitvector [as 别名]
def runTripleDes():
    sxy_list = open(sys.argv[6],'r').read().split('\n')

    Sx = BitVector(hexstring=sxy_list[0].lower())
    Sy = BitVector(hexstring=sxy_list[1].lower())

    if len(Sx) != 164 or len(Sy) != 164:
        raise ValueError("Keys are not the correct size.")

    key_64_list = seperateKeys(Sx, Sy)

    if sys.argv[2] == '-t':
        file_bv = BitVector(textstring=open(sys.argv[1],'r').read())
    elif sys.argv[2] == '-h':
        file_bv = BitVector(hexstring=open(sys.argv[1],'r').read())
    else:
        raise Exception

    if sys.argv[5] == '-e' and len(file_bv)%64 != 0:
        file_bv.pad_from_right(64-(len(file_bv) % 64))

    result = tripleDES(file_bv, key_64_list, sys.argv[5])

    if sys.argv[5] == '-d':
        i = len(result) - 8
        while i > 0:
            if int(result[i::]) != 0:
                break
            i -= 8
        i += 8

        result = result[0:i]


    if sys.argv[5] == '-e':
        print("\n\nOUTPUT (ciphertext):\n\n")
    else:
        print("\n\nOUTPUT (decrypted):\n\n")

    print (hexdump(result.get_text_from_bitvector()))

    if sys.argv[4] == '-t':
        open(sys.argv[3],'w').write(result.get_text_from_bitvector())
    elif sys.argv[4] == '-h':
        open(sys.argv[3],'w').write(result.get_hex_string_from_bitvector())
    else:
        raise Exception

    if len(sys.argv) == 9:
        if sys.argv[8] == '-t':
            verilog_output = BitVector(textstring=open(sys.argv[7],'r').read())
        elif sys.argv[8] == '-h':
            verilog_output = BitVector(hexstring=open(sys.argv[7],'r').read())

        if verilog_output.get_hex_string_from_bitvector() != result.get_hex_string_from_bitvector():
            raise ValueError("Output does not match python!")


    print ("\n")
开发者ID:PSOCER,项目名称:de2i150_ECCDH3DES,代码行数:61,代码来源:new_des.py

示例7: mix_columns

# 需要导入模块: import BitVector [as 别名]
# 或者: from BitVector import get_hex_string_from_bitvector [as 别名]
def mix_columns(state_array):

    oper_m = [[2,3,1,1],
              [1,2,3,1],
              [1,1,2,3],
              [3,1,1,2]]
    mix_matrix = [[0,0,0,0],
                  [0,0,0,0],
                  [0,0,0,0],
                  [0,0,0,0]]

    m = state_array[0][0:8]
    print (m.get_hex_string_from_bitvector())
    y = m.int_val()
    print (type(y))
    print (y)
    print ("mix_columns begin$$$$$$$$$$$$$$$$$$$$$$$$$$$$$")
    state_matrix = []
    for i in range(4):
        rowlis = []
        for j in range(4):
            #print (state_array[i][j*8:j*8+8].get_hex_string_from_bitvector()),
            #print (state_array[i][j*8:j*8+8].int_val())
            rowlis.append(state_array[i][j*8:j*8+8].int_val())
        state_matrix.append(rowlis)
    print (state_matrix)
    for i in range(len(state_matrix)):
        for j in range(len(state_matrix[i])):
            print (state_matrix[i][j]),

    modulus = BitVector(bitstring="100011011")
    for i in range(len(oper_m)):
        for j in range(len(state_matrix[0])):
            bb = BitVector(intVal = 0, size=8)
            for k in range(len(state_matrix)):
                '''
                ss = BitVector(intVal=oper_m[i][k],size=8)^BitVector(intVal=state_matrix[k][j],size=8)
                bb = bb ^ ss
                '''

                a = BitVector(intVal=oper_m[i][k],size=8)
                b = BitVector(intVal=state_matrix[k][j],size=8)
                ss = a.gf_multiply_modular(b,modulus,8)
                bb = bb ^ ss
                #mix_matrix[i][j] += oper_m[i][k]*state_matrix[k][j]
            mix_matrix[i][j] = bb
    print ("mix_matrix******************")
    mix_colums_bv = BitVector(size=0)
    for j in range(4):
        for i in range(4):
            #print (mix_matrix[i][j])
            mix_colums_bv += mix_matrix[i][j]
    print (mix_colums_bv.get_hex_string_from_bitvector())

    return mix_colums_bv
开发者ID:yinuoli1114,项目名称:0409_ComputerAndNetwork_Security_YinuoLi,代码行数:57,代码来源:aes_yinuo.py

示例8: main

# 需要导入模块: import BitVector [as 别名]
# 或者: from BitVector import get_hex_string_from_bitvector [as 别名]
def main():

    key1 = BitVector(hexstring='af4892de13378520'.lower())
    key2 = BitVector(hexstring='beefdead1337abcd')
    key3 = BitVector(hexstring='1337abcdabcdabcd')

    # Sx = BitVector(hexstring='129e4d24 d07531e5 c99ffad6 7da90056 31c44b61 a'.replace(' ',''))
    # Sy = BitVector(hexstring='4927baba d5319b99 41617be0 17a7ee92 a188ce39 c'.replace(' ',''))

    # # input_block = BitVector(textstring='deadbeef')

    # one_nine_two_bit_key = Sx[0:163] + Sy[0:29]

    one_nine_two_bit_key = BitVector(hexstring='39c7311ac36911c635004adf35affcc9d3c6570592593ca4')
    print (len(one_nine_two_bit_key))

    key1 = one_nine_two_bit_key[0:64]
    key2 = one_nine_two_bit_key[64:128]
    key3 = one_nine_two_bit_key[128:192]

    print (one_nine_two_bit_key.get_hex_string_from_bitvector())

    # print (len(key1))
    # print (len(key2))
    # print (len(key3))


    key56_1 = get_encryption_key(key1)
    key56_2 = get_encryption_key(key2)
    key56_3 = get_encryption_key(key3)

    print(key56_1.get_hex_string_from_bitvector())
    print(key56_2.get_hex_string_from_bitvector())
    print(key56_3.get_hex_string_from_bitvector())


    # out1 = des('e', input_block, key56_1)

    # out2 = des('e', out1, key56_2)

    # out3 = des('e', out2, key56_3)

    # print (out3.get_hex_string_from_bitvector())


    data_bv = BitVector(intVal=0,size=64)

    out1 = des('e', data_bv, key56_1)

    out2 = des('e', out1, key56_2)

    out3 = des('e', out2, key56_3)
开发者ID:PSOCER,项目名称:de2i150_ECCDH3DES,代码行数:54,代码来源:des.py

示例9: writeFile

# 需要导入模块: import BitVector [as 别名]
# 或者: from BitVector import get_hex_string_from_bitvector [as 别名]
def writeFile(data_block, filename, type, mode):
    ## Open the output file
    out = open(filename, 'wa')
    ## Depending if we're encrypting or decrypting for the size of byte to write
    ## 256 - Encrypt, 128 - Decrypt
    for data in data_block:
        if type:
            bv = BitVector(intVal = data, size = 256)
        else:
            bv = BitVector(intVal = data, size = 128)
        if mode:
            out.write(bv.get_text_from_bitvector())
        else:
            out.write(bv.get_hex_string_from_bitvector())
开发者ID:ajdunker,项目名称:ECE404,代码行数:16,代码来源:Dunker_RSA_hw06.py

示例10: inv_mix_columns

# 需要导入模块: import BitVector [as 别名]
# 或者: from BitVector import get_hex_string_from_bitvector [as 别名]
def inv_mix_columns(ad_rk):

    oper_m = [[0x0e,0x0b,0x0d,0x09],
              [0x09,0x0e,0x0b,0x0d],
              [0x0d,0x09,0x0e,0x0b],
              [0x0b,0x0d,0x09,0x0e]]
    mix_matrix = [[0,0,0,0],
                  [0,0,0,0],
                  [0,0,0,0],
                  [0,0,0,0]]
    zz = BitVector(intVal=0xe,size=8)
    print ("zz")
    print (zz)
    matrix = []
    for i in range(4):
        rowlis = []
        for j in range(4):
            rowlis.append(ad_rk[32*j+8*i:32*j+8*i+8])
        matrix.append(rowlis)
    for i in range(4):
        for j in range(4):
            print (matrix[i][j].get_hex_string_from_bitvector()),
        print ("")
    modulus = BitVector(bitstring="100011011")
    for i in range(len(oper_m)):
        for j in range(len(matrix[0])):
            bb = BitVector(intVal = 0, size=8)
            for k in range(len(matrix)):
                a = BitVector(intVal=oper_m[i][k],size=8)
                b = matrix[k][j]
                ss = a.gf_multiply_modular(b,modulus,8)
                bb = bb ^ ss
                #mix_matrix[i][j] += oper_m[i][k]*state_matrix[k][j]
            mix_matrix[i][j] = bb
    mix_colums_bv = BitVector(size=0)
    for j in range(4):
        for i in range(4):
            #print (mix_matrix[i][j])
            mix_colums_bv += mix_matrix[i][j]
    print (mix_colums_bv.get_hex_string_from_bitvector())

    return mix_colums_bv
开发者ID:yinuoli1114,项目名称:0409_ComputerAndNetwork_Security_YinuoLi,代码行数:44,代码来源:aes_yinuo.py

示例11: encrypt

# 需要导入模块: import BitVector [as 别名]
# 或者: from BitVector import get_hex_string_from_bitvector [as 别名]
def encrypt(inputfile, outputfile, public_key_file):

    # Get data in 128 bit blocks
    data = get_input_blocks(inputfile)

    # Get the public key from file
    e, n = get_public_key(public_key_file)

    # Encrypt each block and write to file
    with open(outputfile, 'w') as f :

        # Encrypted each 128 bit block of data
        for block in data :

            # use binary exponential script
            en_int = binary_exp( int(block), e, n )

            #convert to bitvector for each hex printing
            en_block = BitVector( size = 256, intVal=en_int )

            # write encrypted block to file
            f.write(en_block.get_hex_string_from_bitvector())
开发者ID:sheel7,项目名称:ECE404,代码行数:24,代码来源:Sheeley_RSA_hw06.py

示例12: RSA_encrypt

# 需要导入模块: import BitVector [as 别名]
# 或者: from BitVector import get_hex_string_from_bitvector [as 别名]
def RSA_encrypt(inputfile, public_key):
    f = open (inputfile,'r')
    content = BitVector(filename=inputfile)
    print (content)
    ciphers_bv = BitVector(size=0)
    while (content.more_to_read):

        package = content.read_bits_from_file(128)
        print ("package")
        print (package)
        print (package.get_hex_string_from_bitvector())

        newlinebv = BitVector(textstring='\n')
        print (newlinebv)
        while(len(package) < 128):
            package += newlinebv
        print (package.get_hex_string_from_bitvector())

        package.pad_from_left(128)
        print (package.get_hex_string_from_bitvector())
        pa_int = package.int_val()
        print (pa_int)
        cipher_int = pow(pa_int,public_key[0],public_key[1])
        print (cipher_int)
        cipher_hex = hex(cipher_int)
        cipher_bv = BitVector(intVal=cipher_int, size = 256)
        ciphers_bv += cipher_bv

    fo = open("output.txt",'w')

    #rr = BitVector(intVal=cipher_int, size = 256)
    #rrr=rr.get_hex_string_from_bitvector()
    #print (rrr)


    fo.write(ciphers_bv.get_hex_string_from_bitvector())
开发者ID:yinuoli1114,项目名称:0409_ComputerAndNetwork_Security_YinuoLi,代码行数:38,代码来源:Li_RSA_hw06.py

示例13: main

# 需要导入模块: import BitVector [as 别名]
# 或者: from BitVector import get_hex_string_from_bitvector [as 别名]
def main():

    ## Generate 3 sets of public and private keys
    pub1, priv1, p1, q1, e = createKeys(3)
    pub2, priv2, p2, q2, e = createKeys(3)
    pub3, priv3, p3, q3, e = createKeys(3)

    with open("private1.txt", 'w') as f :
            f.write("d="+str(priv1[0])+"\n")
            f.write("n="+str(p1*q1)+"\n")
            f.write("p="+str(p1)+"\n")
            f.write("q="+str(q1)+"\n")

    with open("private2.txt", 'w') as f :
        f.write("d="+str(priv2[0])+"\n")
        f.write("n="+str(p2*q2)+"\n")
        f.write("p="+str(p2)+"\n")
        f.write("q="+str(q2)+"\n")

    with open("private3.txt", 'w') as f :
        f.write("d="+str(priv3[0])+"\n")
        f.write("n="+str(p3*q3)+"\n")
        f.write("p="+str(p3)+"\n")
        f.write("q="+str(q3)+"\n")

    ## Encrypt 1 file 3 times with each of the different public keys
    encrypted1 = encrypt("message.txt", pub1)
    encrypted2 = encrypt("message.txt", pub2)
    encrypted3 = encrypt("message.txt", pub3)

    ## Write these files out
    writeFile(encrypted1, "enc1.txt", True, False)
    writeFile(encrypted2, "enc2.txt", True, False)
    writeFile(encrypted3, "enc3.txt", True, False)

    ## Calculate N the product of all the values of n
    N = pub1[1] * pub2[1] * pub3[1]

    ## Caluclate Ni = N / ni
    N1 = N / pub1[1]
    N2 = N / pub2[1]
    N3 = N / pub3[1]

    ## Get BitVector representations of Ni and ni for use in BitVector multiplicative inverse
    bvM1 = BitVector(intVal = pub1[1])
    bvM2 = BitVector(intVal = pub2[1])
    bvM3 = BitVector(intVal = pub3[1])
    bv1 = BitVector(intVal = N1)
    bv2 = BitVector(intVal = N2)
    bv3 = BitVector(intVal = N3)

    ## Caluclate the multiplicative inverse of each Ni modulo ni
    C1 = int(bv1.multiplicative_inverse(bvM1))
    C2 = int(bv2.multiplicative_inverse(bvM2))
    C3 = int(bv3.multiplicative_inverse(bvM3))

    crackedBV = BitVector(size = 0)

    ## By CRT recover M^3 by the below equation
    for z in range(len(encrypted1)):
        x = (encrypted1[z] * N1 * C1 + encrypted2[z] * N2 * C2 + encrypted3[z] * N3 * C3) % N
        ## Recover M
        cINT = solve_pRoot(3, x)
        crackedBV += BitVector(intVal = cINT, size = 128)

    ## Write out the recovered file
    out = open("cracked.txt", 'wa')
    out.write(crackedBV.get_text_from_bitvector())
    out = open("HEXcracked.txt", 'wa')
    out.write(crackedBV.get_hex_string_from_bitvector())
开发者ID:ajdunker,项目名称:ECE404,代码行数:72,代码来源:Dunker_breakRSA_hw06.py

示例14: BitVector

# 需要导入模块: import BitVector [as 别名]
# 或者: from BitVector import get_hex_string_from_bitvector [as 别名]
key = key.strip()                                                             #(M)

# Reduce the key to a bit array of size BLOCKSIZE:
key_bv = BitVector(bitlist = [0]*BLOCKSIZE)                                   #(N)
for i in range(0,len(key) // numbytes):                                       #(O)
    keyblock = key[i*numbytes:(i+1)*numbytes]                                 #(P)
    key_bv ^= BitVector( textstring = keyblock )                              #(Q)

# Create a bitvector for storing the ciphertext bit array:
msg_encrypted_bv = BitVector( size = 0 )                                      #(R)

# Carry out differential XORing of bit blocks and encryption:
previous_block = bv_iv                                                        #(S)
bv = BitVector( filename = sys.argv[1] )                                      #(T)
while (bv.more_to_read):                                                      #(U)
    bv_read = bv.read_bits_from_file(BLOCKSIZE)                               #(V)
    if len(bv_read) < BLOCKSIZE:                                              #(W)
        bv_read += BitVector(size = (BLOCKSIZE - len(bv_read)))               #(X)
    bv_read ^= key_bv                                                         #(Y)
    bv_read ^= previous_block                                                 #(Z)
    previous_block = bv_read.deep_copy()                                      #(a)
    msg_encrypted_bv += bv_read                                               #(b)

# Convert the encrypted bitvector into a hex string:    
outputhex = msg_encrypted_bv.get_hex_string_from_bitvector()                  #(c)

# Write ciphertext bitvector to the output file:
FILEOUT = open(sys.argv[2], 'w')                                              #(d)
FILEOUT.write(outputhex)                                                      #(e)
FILEOUT.close()                                                               #(f)
开发者ID:jain98,项目名称:PurdueProgramming,代码行数:32,代码来源:EncryptForFun.py

示例15: aesEncryption

# 需要导入模块: import BitVector [as 别名]
# 或者: from BitVector import get_hex_string_from_bitvector [as 别名]
def aesEncryption(inputfile,roundkeys):
    content = BitVector(filename=inputfile)
    # print (type(content))
    # print (content)
    packages = BitVector(size=0)
    uu = 0
    np = 0
    while (content.more_to_read):
        uu += 1
        package = content.read_bits_from_file(128)
        # print (type(package))
        # print (package.get_hex_string_from_bitvector())

        #np = 0

        if package.length() != 128:
            np = package._getsize()
            # print (np)
            package.pad_from_right(128-package.length())
            # print ("padding [email protected]@@@@@@@@@@@@@@@     @@@@@@@@@@@@@@@@@@@")
            # print (package.get_hex_string_from_bitvector())
        # print ("RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR                RRRRRRRRRRRRRRRRR")
        # print (uu)

        first4w = BitVector(size = 0)
        for j in range(len(roundkeys[0])):
            first4w += roundkeys[0][j]
        # print ("first4w")
        # print (first4w.get_hex_string_from_bitvector())
        packager = package ^ first4w
        # print ("packager")
        # print (packager.get_hex_string_from_bitvector())




        for ri in range(1,11):
            print (str(ri)+" round begin &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&")
            subbytes = sub_bytes(packager)
            # print ("subbytes")
            # print (subbytes.get_hex_string_from_bitvector())
            # print (package.get_hex_string_from_bitvector())
            state_array = shift_rows(subbytes)
            if ri < 10:
                mix_colums_bv = mix_columns(state_array)
                # print ("mix_colums_bv")
                # print (mix_colums_bv.get_hex_string_from_bitvector())

            if ri < 10:
                added_rk_block = add_round_key(mix_colums_bv,roundkeys,ri)
            else:
                tenthstate = BitVector(size=0)
                for j in range(4):
                    for i in range(4):
                        tenthstate += state_array[i][j*8:j*8+8]
                # print ("tenthstate")
                # print (tenthstate.get_hex_string_from_bitvector())
                added_rk_block = add_round_key(tenthstate,roundkeys,ri)
            # print ("added_rk_block")
            # print (added_rk_block.get_hex_string_from_bitvector())
            packager = added_rk_block
        # print ("packager         WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW")
        # print (uu)
        # print (packager.get_hex_string_from_bitvector())
        packages += packager
    outfile = "encryptedtext.txt"
    fo = open(outfile,'w')
    hexstr = packages.get_hex_string_from_bitvector()
    fo.write(hexstr)
    return np
开发者ID:yinuoli1114,项目名称:0409_ComputerAndNetwork_Security_YinuoLi,代码行数:72,代码来源:ece404_hw04_Li.py


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