Exemple #1
0
def eccDecrypt(data_cipher, privateKey):
    "Giải mã ECC với đầu vào là chuỗi bytes từ hình ảnh đã mã hoá"

    c = data_cipher[:64]
    C1 = (OS2IP(c[:32]), OS2IP(c[-32:]))
    C = EccMath.scalar_Point(privateKey, C1)
    C = EccMath.negatives_Point(C)

    data_cipher = data_cipher[64:]
    points = []
    for i in range(0, len(data_cipher), 64):
        data = data_cipher[i:i + 64]
        x = OS2IP(data[:32])
        y = OS2IP(data[-32:])
        points.append((x, y))

    plain_data = []
    for point in points:
        plain_data.append(elgamalDe(C, point))

    plain_bytes = []
    for j in plain_data:
        plain_bytes.append(I2OSP(j, 31))

    plain_data = b''.join(plain_bytes)

    plain_data = remove_padding(plain_data)

    return plain_data
Exemple #2
0
def eccDecrypt(data_cipher, privateKey):
    c = data_cipher[:64]
    C1 = (OS2IP(c[:32]), OS2IP(c[-32:]))
    C = EccMath.scalar_Point(privateKey, C1)
    C = EccMath.negatives_Point(C)

    data_cipher = data_cipher[64:]
    points = []
    for i in range(0, len(data_cipher), 64):
        data = data_cipher[i:i+64]
        x = OS2IP(data[:32])
        y = OS2IP(data[-32:])
        points.append((x, y))

    plain_data = []
    for point in points:
        plain_data.append(elgamalDecrypt(C, point))

    plain_bytes = []
    for j in plain_data:
        plain_bytes.append(I2OSP(j, 31))

    plain_data = b''.join(plain_bytes)

    return plain_data