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


Python BitVector.int_val方法代码示例

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


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

示例1: des

# 需要导入模块: import BitVector [as 别名]
# 或者: from BitVector import int_val [as 别名]
def des( s_box, input_file, output_file, keys ): 
    FILEOUT = open( output_file, 'ab' ) 
    bv = BitVector( filename = input_file )
    while (bv.more_to_read ):
        bitvec = bv.read_bits_from_file( 64 )   ## assumes that your file has an integral
        leng = bitvec.length()                                        ## multiple of 8 bytes. If not, you must pad it.
        pad = 64 - leng
        bitvec.pad_from_right(pad)
        [LE, RE] = bitvec.divide_into_two()   
        for i in range(16):        
            righty = RE.permute(expansion_permutation)
            resultxor = righty ^ keys[i]
            #s substitution
            temp_bv = BitVector(size = 6)
            row_bv = BitVector(size = 2)
            col_bv = BitVector(size = 4)
            ini=0
            fin=6
            inf=0
            fif=4
            final_bv = BitVector(size = 32)
            for k in range(8):
                temp_bv = resultxor[ini:fin]
                row_bv[0:1] = temp_bv[0:1]
                row_bv[1:2] = temp_bv[5:6]
                col_bv = temp_bv[1:5]
                row = row_bv.int_val()#get row
                col = col_bv.int_val()#get column      
                    #get stuff from sbox 
                newd = s_box[k][row][col]
                temp = BitVector(intVal = newd)
                temp_leng = temp.length()
                lpad = 4 - temp_leng
                temp.pad_from_left(lpad)
                final_bv[inf:fif] = temp
                inf = inf + 4
                fif = fif + 4
                ini = ini + 6#increase to the next thing
                fin = fin + 6#increase to th next chunck
                #permutation with p box
            last_p = final_bv.permute(p_box_permutation)
                #xor with le result = RE
            temporal = RE
            RE = last_p ^ LE
            LE = temporal #le equals old re     
            #for loop done
            #put left + right on output file
        file_writebv =  RE + LE
        file_writebv.write_to_file(FILEOUT)
开发者ID:igalfsg,项目名称:ECE404,代码行数:51,代码来源:Average_flegmann.py

示例2: RSA_decrypt

# 需要导入模块: import BitVector [as 别名]
# 或者: from BitVector import int_val [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: print

# 需要导入模块: import BitVector [as 别名]
# 或者: from BitVector import int_val [as 别名]
print("\nBit vector constructed from integer 5678:")
print(bv)                                    # 1011000101110
print("\nBit vector constructed from integer 0:")
bv = BitVector(intVal=0)
print(bv)                                    # 0
print("\nBit vector constructed from integer 2:")
bv = BitVector(intVal=2)
print(bv)                                    # 10
print("\nBit vector constructed from integer 3:")
bv = BitVector(intVal=3)
print(bv)                                    # 11
print("\nBit vector constructed from integer 123456:")
bv = BitVector(intVal=123456)
print(bv)                                    # 11110001001000000
print("\nInt value of the previous bit vector as computed by int_val():")
print(bv.int_val())                         # 123456
print("\nInt value of the previous bit vector as computed by int():")
print(int(bv))                               # 123456

# Construct a bit vector from a very large integer:
x = 12345678901234567890123456789012345678901234567890123456789012345678901234567890
bv = BitVector(intVal=x)
print("\nHere is a bit vector constructed from a very large integer:")
print(bv)
print("The integer value of the above bit vector is:%d" % int(bv))

# Construct a bit vector directly from a file-like object:
import io
x = "111100001111"
x = ""
if sys.version_info[0] == 3:
开发者ID:gsnedders,项目名称:BitVector,代码行数:33,代码来源:BitVectorDemo.py


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