資源簡介
本資源內部包含兩個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
- 上一篇:ArcEngine開發鷹眼功能C#實現
- 下一篇:基于sql與c#的學生選課系統
評論
共有 條評論