赞
踩
密码学实验:ECC算法实现
1.实验内容
2.运行结果:
1.椭圆曲线上的点集
2.椭圆曲线生成元以及对应的阶
3.加解密算法
代码如下:
/*
(1)编程计算该椭圆曲线上所有在有限域GF(89)上的点;
(2)编程实现椭圆曲线上任意一个点P(例如P=(12,5))的倍点运算的递归算法,即计算k*P( k=2,3,…);(重点!)
(3)利用此递归算法找出椭圆曲线上的所有生成元G以及它们的阶n,即满足n*G=O;
(4)设计实现某一用户B的公钥、私钥算法,即得到public key=(n, G, PB, Ep(a, b))
secure key=nB(小于n)
(5)假如用户A发送明文消息“yes”并加密传输给用户B,用户B接收消息后要能解密为明文。试用ECC密码体制实现此功能。
*/
#include
#include
#include
#include
#include
#define MAX 100
typedef struct point{
int point_x;
int point_y;
}Point;
typedef struct ecc{
struct point p[MAX];
int len;
}ECCPoint;
typedef struct generator{
Point p;
int p_class;
}GENE_SET;
void get_all_points();
int int_sqrt(int s);
Point timesPiont(int k,Point p);
Point add_two_points(Point p1,Point p2);
int inverse(int n,int b);
void get_generetor_class();
void encrypt_ecc();
void decrypt_ecc();
int mod_p(int s);
void print();
int isPrime(int n);
char alphabet[26]="abcdefghijklmnopqrstuvwxyz";
int a=-1,b=0,p=89;//椭圆曲线为E89(-1,0): y2=x3-x (mod 89)
ECCPoint eccPoint;
GENE_SET geneSet[MAX];
int geneLen;
char plain[]="yes";
int m[MAX];
int cipher[MAX];
int nB;//私钥
Point P1,P2,Pt,G,PB;
Point Pm;
int C[MAX];
int main()
{
get_generetor_class();
encrypt_ecc();
decrypt_ecc();</
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。