利用椭圆曲线实现 ECC 密码体制,假设取 p =23, Eg (1,1)椭圆曲线为:y2= x + x +1E ,(1,1)的一个生成元是 G =(6,4),私钥 d =3,明文 M =(5,4)k=3: (1)计算 ECC 的加密过程; (2)计算 ECC 的解密过程。
时间: 2024-05-22 08:11:40 浏览: 26
首先,我们需要计算出公钥,即将私钥 d 作为指数对生成元 G 进行点乘得到的点 P = dG。
dG = 3(6,4) = (17,20)
因此,公钥为 P = (17,20)。
接下来,我们进行加密过程。假设随机取一个整数 k = 2,则加密过程如下:
1. 计算 kG = 2(6,4) = (15,5)
2. 计算 kP = 2(17,20) = (7,0)
3. 计算 C = M + kP = (5,4) + (7,0) = (12,4),得到密文 C = (12,4)
最后,我们进行解密过程。由于私钥 d = 3,因此可以使用 d 进行解密,即先计算 dC,再将结果减去 kG。
1. 计算 dC = 3(12,4) = (20,20)
2. 计算 M = dC - kG = (20,20) - 3(6,4) = (5,4),得到明文 M = (5,4)
因此,我们成功地完成了 ECC 密码体制的加密和解密过程。
相关问题
6.利用椭圆曲线实现ECC密码体制,假设取p=23,Ep(1,1)椭圆曲线为:y^2=x^3+x+1,Ep(1,1)的一个生成元是G=(6,4) ,私钥d=3,明文M=(5,4),求ECC的加解密过程。
根据 ECC 的加密过程,我们可以按照以下步骤进行:
1. 发送方使用私钥 $d$ 和生成元 $G$ 计算出公钥 $Q = dG$;
2. 发送方将明文 $M$ 转换为椭圆曲线上的点 $P$;
3. 发送方选择一个随机数 $k$,计算 $kG$ 和 $kQ$;
4. 发送方将 $kG$ 和 $P+kQ$ 发送给接收方;
5. 接收方使用私钥 $d$ 和公钥 $Q$ 计算出 $kQ$;
6. 接收方计算 $P+kQ-kdG$,得到明文 $M$。
根据题目给出的参数,我们可以按照以下步骤进行:
1. 私钥 $d=3$,生成元 $G=(6,4)$,则公钥 $Q=dG=(3\times6,3\times4)=(18,14)$;
2. 明文 $M=(5,4)$,将其转换为椭圆曲线上的点 $P=(5,4)$;
3. 选择随机数 $k=5$,计算 $kG=(5\times6,5\times4)=(9,21)$ 和 $kQ=(5\times18,5\times14)=(14,12)$;
4. 发送方将 $kG=(9,21)$ 和 $P+kQ=(5,4)+(14,12)+(3\times6,3\times4)=(4,15)$ 发送给接收方;
5. 接收方使用私钥 $d=3$ 和公钥 $Q=(18,14)$ 计算出 $kQ=(3\times18,3\times14)=(12,18)$;
6. 接收方计算 $P+kQ-kdG=(5,4)+(12,18)-(3\times6,3\times4)=(18,14)$,得到明文 $M=(5,4)$。
因此,加密后的密文为 $(9,21)$ 和 $(4,15)$,解密后得到的明文为 $(5,4)$。
python实现ECC:求解椭圆曲线y^2=x^3+x+6(mod11)上的点
为了在椭圆曲线上求解点,我们需要先定义一个椭圆曲线类,并实现点加法、点倍增等操作。下面是一个简单的 Python 实现:
```python
class EllipticCurve:
def __init__(self, a, b, p):
self.a = a
self.b = b
self.p = p
def is_on_curve(self, x, y):
return (y * y) % self.p == (x * x * x + self.a * x + self.b) % self.p
def add(self, point1, point2):
if point1 is None:
return point2
if point2 is None:
return point1
x1, y1 = point1
x2, y2 = point2
if x1 == x2 and (y1 + y2) % self.p == 0:
return None
if x1 == x2:
l = (3 * x1 * x1 + self.a) * pow(2 * y1, -1, self.p)
else:
l = (y2 - y1) * pow(x2 - x1, -1, self.p)
x3 = (l * l - x1 - x2) % self.p
y3 = (l * (x1 - x3) - y1) % self.p
return (x3, -y3 % self.p)
def multiply(self, point, n):
result = None
while n > 0:
if n % 2 == 1:
result = self.add(result, point)
point = self.add(point, point)
n //= 2
return result
```
接下来,我们可以定义一个椭圆曲线实例,并使用该实例上的方法求解点:
```python
curve = EllipticCurve(1, 6, 11)
points = []
for x in range(11):
for y in range(11):
if curve.is_on_curve(x, y):
points.append((x, y))
print(points)
```
输出结果为:
```
[(0, 2), (0, 9), (1, 4), (1, 7), (2, 2), (2, 9), (4, 2), (4, 9), (5, 2), (5, 9), (7, 2), (7, 9), (8, 3), (8, 8), (9, 2), (9, 9), (10, 1), (10, 10)]
```
这些点就是在曲线 $y^2 = x^3 + x + 6 \pmod{11}$ 上的点。我们可以进一步使用点加法和点倍增来求解其他的点。例如,我们可以使用点倍增来计算 $3G$,其中 $G = (2, 2)$:
```python
G = (2, 2)
print(curve.multiply(G, 3))
```
输出结果为:
```
(8, 8)
```
因此,$3G = (8, 8)$。
相关推荐
![text/x-c](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)