资源简介
python3环境下的PBC库,可用于双线性配对计算的使用
python3环境下的PBC库,可用于双线性配对计算的使用
python3环境下的PBC库,可用于双线性配对计算的使用

代码片段和文件信息
#! /usr/bin/env python3
“““
KSW.py
Written by Geremy Condra
Licensed under GPLv3
Released 15 October 2009
An implementation of the Katz-Sahai-Waters predicate
encryption scheme in Python3.
“““
from pypbc import *
#############################################
# Utilities #
#############################################
def dot_product(x y n):
“““Takes the dot product of lists x and y over F_n“““
if len(x) != len(y):
raise ValueError(“x and y must be the same length!“)
if not isinstance(n int):
raise ValueError(“n must be an integer!“)
return sum([(x_i * y[i]) % n for i x_i in enumerate(x)])
#############################################
# Cryptosystem #
#############################################
class PublicKey:
g_G_p = None
g_G_r = None
Q = None
vector = None
def __init__(self gen_p gen_r Q vector):
self.g_G_p = gen_p
self.g_G_r = gen_r
self.Q = Q
self.vector = vector
class MasterSecretKey:
p = None
q = None
r = None
g_G_q = None
Hs = None
def __init__(self p q r g_G_q Hs):
self.p = p
self.q = q
self.r = r
self.g_G_q = g_G_q
self.Hs = Hs
class Cryptosystem:
def __init__(self security) -> “(PK SK)“:
self.security = security
# select p q r
p = get_random_prime(100)
q = get_random_prime(100)
r = get_random_prime(100)
# make n
self.n = p*q*r
# build the params
params = Parameters(n=self.n)
# build the pairing
self.pairing = Pairing(params)
# find the generators for the G_p G_q and G_r subgroups
g_G_p = Element.random(self.pairing G1)**(q*r)
g_G_r = Element.random(self.pairing G1)**(p*q)
g_G_q = Element.random(self.pairing G1)**(p*r)
# choose R0
R0 = g_G_r ** Element.random(self.pairing Zr)
# choose the random R‘s
Rs = [(g_G_r**Element.random(self.pairing Zr) g_G_r**Element.random(self.pairing Zr)) for i in range(security)]
hs = [(g_G_p**Element.random(self.pairing Zr) g_G_p**Element.random(self.pairing Zr)) for i in range(security)]
# choose the random H‘s
Hs = []
for i in range(security):
Hs.append((hs[i][0] * Rs[i][0] hs[i][1] * Rs[i][1]))
# calculate Q
Q = g_G_q * R0
# build the public and master secret keys
self.pk = PublicKey(g_G_p g_G_r Q Hs)
self.sk = MasterSecretKey(p q r g_G_q hs)
def keygen(self v: “description of a predicate“) -> “SK_f“:
R5 = self.pk.g_G_r**Element.random(self.pairing Zr)
Q6 = self.sk.g_G_q**Element.random(self.pairing Zr)
Rs = []
for i in range(self.security):
# build r1
r1 = Element(self.pairing Zr get_random(self.sk.p))
# build r2
r2 = Element(self.pairing Zr get_random(self.sk.p))
Rs.append((r1 r2))
f1 = Element(self.pairing Zr get_random(self.sk.q))
f2 = Element(self.pairing Zr get_random(self.sk.q))
K = R5*Q6
for pos in range(self.security):
# get h1 h2
h1 h2 = self.sk.Hs[pos]
# get r1 r2
r1 r2 = Rs[pos]
# form the intermediate value
i1 = h1**(-r1)
i2 = h2**(-r2)
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2017-11-21 17:22 pypbc-master\
文件 1480 2017-11-21 17:22 pypbc-master\INSTALL
文件 7601 2017-11-21 17:22 pypbc-master\KSW.py
文件 1070 2017-11-21 17:22 pypbc-master\LICENSE
文件 683 2017-11-21 17:22 pypbc-master\Makefile
文件 44874 2017-11-21 17:22 pypbc-master\pypbc.c
文件 1912 2017-11-21 17:22 pypbc-master\pypbc.h
文件 390 2017-11-21 17:22 pypbc-master\setup.py
文件 9837 2017-11-21 17:22 pypbc-master\test.py
相关资源
- Python-BDD100K大规模多样化驾驶视频数据
- Instant Pygame for Python Game Development How
- Biopython Tutorial
- Think Python 2nd
- 一个小小的表白程序(python)
- Python课堂笔记(高淇400集第一季)
- 二级考试python试题12套(包括选择题和
- pywin32_python3.6_64位
- python+ selenium教程
- PycURL(Windows7/Win32)Python2.7安装包 P
- 英文原版-Scientific Computing with Python
- 7.图像风格迁移 基于深度学习 pyt
- 基于Python的学生管理系统
- A Byte of Python(简明Python教程)(第
- Python实例174946
- Python 人脸识别
- Python 人事管理系统
- 基于python-flask的个人博客系统
- 计算机视觉应用开发流程
- python 调用sftp断点续传文件
- python socket游戏
- 基于Python爬虫爬取天气预报信息
- python函数编程和讲解
- Python开发的个人博客
- 基于python的三层神经网络模型搭建
- python实现自动操作windows应用
- python人脸识别(opencv)
- python 绘图(方形、线条、圆形)
- python疫情卡UN管控
- python 连连看小游戏源码
评论
共有 条评论