梗概

Python密码协议释秘

示例

import binascii
def text2int(msg):
    print (msg)
    msg = msg.encode()
    hexstr = binascii.hexlify(msg)
    print (hexstr)

    back2hex = format(integer_m, 'x')
    print (back2hex)

    evenpad = ('0' * (len(back2hex) % 2)) + back2hex

    plaintext = binascii.unhexlify(evenpad)
    print (plaintext)

text2int("Hello World")

Python密码混淆数据

示例

import sys
import numpy as np

def cipher_encryption(plain, key):

    len_chk = 0
    if len(plain) % 2 != 0:
        plain += "0"
        len_chk = 1

    # msg to matrices
    row = 2
    col = int(len(plain)/2)
    msg2d = np.zeros((row, col), dtype=int)

    itr1 = 0
    itr2 = 0
    for i in range(len(plain)):
        if i%2 == 0:
            msg2d[0][itr1]= int(ord(plain[i]) - 65)
            itr1 += 1
        else:
            msg2d[1][itr2] = int(ord(plain[i]) - 65)
            itr2 += 1

    # finding multiplicative inverse
    for i in range(26):
        temp_inv = deter * i
        if temp_inv % 26 == 1:
            mul_inv = i
            break
        else:
            continue

    if mul_inv == -1:
        print("Invalid key")
        sys.exit()

    encryp_text = ""
    itr_count = int(len(plain)/2)
    if len_chk == 0:
        for i in range(itr_count):
            temp1 = msg2d[0][i] * key2d[0][0] + msg2d[1][i] * key2d[0][1]
            encryp_text += chr((temp1 % 26) + 65)
            temp2 = msg2d[0][i] * key2d[1][0] + msg2d[1][i] * key2d[1][1]
            encryp_text += chr((temp2 % 26) + 65)
    else:
        for i in range(itr_count-1):
            temp1 = msg2d[0][i] * key2d[0][0] + msg2d[1][i] * key2d[0][1]
            encryp_text += chr((temp1 % 26) + 65)
            temp2 = msg2d[0][i] * key2d[1][0] + msg2d[1][i] * key2d[1][1]
            encryp_text += chr((temp2 % 26) + 65)

    print("Encrypted text: {}".format(encryp_text))
    return encryp_text

def cipher_decryption(cipher, key):

    # if message length is an odd number, place a zero at the end.
    len_chk = 0
    if len(cipher) % 2 != 0:
        cipher += "0"
        len_chk = 1

    # msg to matrices
    row = 2
    col = int(len(cipher)/2)
    msg2d = np.zeros((row, col), dtype=int)

    itr1 = 0
    itr2 = 0
    for i in range(len(cipher)):
        if i%2 == 0:
            msg2d[0][itr1]= int(ord(cipher[i]) - 65)
            itr1 += 1
        else:
            msg2d[1][itr2] = int(ord(cipher[i]) - 65)
            itr2 += 1

Python流密码和分组密码

Python隐藏和读取加密图像

Python消息验证码

Python公钥基础设施

Python PKI-RSA和ECC加密消息

https://embed.notionlytics.com/wt/ZXlKd1lXZGxTV1FpT2lKa01HRTJaREkwWlRKaE4yWTBaalZpWWpnMFpEUTBNVEpoWkRjd01HTTFNaUlzSW5kdmNtdHpjR0ZqWlZSeVlXTnJaWEpKWkNJNklsZHNTR2hsVEZSUFdXeHpaVmRhUW1ZNU1YQmxJbjA9