• 大小: 2KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-06-04
  • 语言: C#
  • 标签: Csharp  ECC  

资源简介

本资源内部包含两个CS文件,一个是Program.cs,另一个就是ECC.cs。Program.cs包含怎么将明文编码方式。

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft;

namespace _ECC_Graduation_Design_Algorithms
{
    class ECCurve
    {
        #region 椭圆曲线定义
        public const double Inf = Double.PositiveInfinity;
        private  long _a;
        public long a
        {
            get { return _a; }
            set { _a = value; }
        }
        private long _b;
        public long b
        {
            get { return _b; }
            set { _b = value; }
        }
        private long _p;
        public long p
        {
            get { return _p; }
            set { _p = value; }
        }
        private double[] _G = new double[2];
        public double[] G
        {
            get { return _G; }
            set { _G = value; }
        }

        public ECCurve(long along blong pdouble Gxdouble Gy)
        {
            this._a = a;
            this._b = b;
            this._p = p;
            this._G[0] = Gx;
            this._G[1] = Gy;
        }
        #endregion

        #region 全局变量
        
        //私钥
        public double k = 25;

        //公钥
        public double[] K = new double[2];

        public double resx;
        public double resy;
        public double r = 6;
        public double[] C1 = new double[2];
        public double[] C2 = new double[2];
        #endregion

        #region 加法模块
        //z是斜率
        //pos返回点坐标
        public double[] Add(double x1 double y1 double x2 double y2)
        {
            double[] pos = new double[2];
            double z;
            if (x1==x2&&y1==y2)
            {
                z = modfrac(3 * x1*x1 + a 2 * y1 p);
                resx = Mod((z * z - x1 - x2)p);
                resy = Mod((z * (x1 - resx) - y1) p);

            }
            if (x1 == x2 && y1 != y2)
            {
                resx = Inf;
                resy = Inf;
            }

            if (x1!=x2)
            {
                z = modfrac(y2-y1x2-x1p);
                resx = Mod (z *z - x1 - x2  p);
                resy = Mod(z * (x1 - (double)resx) - y1 p);
            }
            pos[0] = (double)resx;
            pos[1] = (double)resy;
            return pos;
        }
        #endregion

        #region 取模运算
        //整数取模运算
        public double Mod(double x double y)
        {
            double ans= 0;
            if (y!=0)
            {
                ans =  x - y * Math.Floor(x / y);
            }
            return ans;
        }
        //分数取模运算
        public double modfrac(double ndouble ddouble m)
        {
            n = (double)Math.IEEERemainder( n  m);
            d = (double)Math.IEEERemainder(d m);
            long i = 1;
            while ((double)Math.IEEERemainder(d*im)!=1)
            {
                i = i+1;
            }
            return (double)Math.IEEERema

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     文件        2082  2019-04-20 16:32  Program.cs
     文件        5051  2019-04-20 16:32  ECC.cs

评论

共有 条评论