




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、精選優(yōu)質(zhì)文檔-傾情為你奉上using System;using System.Collections.Generic;using System.Globalization;using System.Linq;using System.Text;using System.Threading.Tasks;namespace ConsoleApplication3 class Class1 point A = new point(11, 4); point B = new point(120, 41);/公鑰 public const int k = 9; public const int a =
2、5; public const int b = 37; public const int p = 127; public const int r = 7; public struct point public int x; public int y; public point(int x, int y) this.x = x; this.y = y; public point(point p) this.x = p.x; this.y = p.y; public int getX_1(int x, int mod) int Q, X1, X2, X3, Y1, Y2, Y3, T1, T2,
3、T3; X1 = 1; X2 = 0; X3 = mod; Y1 = 0; Y2 = 1; Y3 = (x % mod + mod) % mod;/獲得正整數(shù) while (Y3 != 1) Q = X3 / Y3; T1 = X1 - Q * Y1; T2 = X2 - Q * Y2; T3 = X3 - Q * Y3; X1 = Y1; X2 = Y2; X3 = Y3; Y1 = T1; Y2 = T2; Y3 = T3; return Y2; /獲得其乘法逆元 public point chen(point b, int n) point q = b; n = n - 1; for (
4、int i = 1; i < n; i+) q = jia(q, b); return q; public point jia(point pa, point pb) int k; if (bi(pa, pb) k = (3 * pa.x * pa.x + a) * getX_1(2 * pa.y, p) % p;/必須使用正整數(shù)。這里pa.y的值不能取0. /當取0時,這就不能進行這個計算了,因為 pa = -pb了,則,應(yīng)該進行一個判斷。但是,這樣的結(jié)果是 O,是不在橢圓曲線上的,不能進行輸出的值。 /這里是有一個周期數(shù)在,對于容易一個基值的也就是先給出的A來說,它有一個周期n,使n
5、A = O,而這里所有參數(shù)的選取值 /都小于n,使其不會達到O,保證了不會出錯,應(yīng)該是這樣吧。 else k = (pb.y - pa.y) * getX_1(pb.x - pa.x, p) % p; point c = new point(); c.x = (k * k - pa.x - pb.x) % p; c.y = (k * (pa.x - c.x) - pa.y) % p; c.x = (c.x + p) % p; c.y = (c.y + p) % p; return c; public bool bi(point pa, point pb) return pa.x = pb.x
6、&& pa.y = pb.y; public string DCode(string input) string output = "" point M, P1, P2; for (int i = 0; i < input.Length; ) P1.x = inputi+; P1.y = inputi+; P2.x = inputi+; P2.y = inputi+; Dictionary<int, point> CC = new Dictionary<int, point>(); CC.Add(3, P1); CC.Add(4
7、, P2); M = DCodePoint(CC); output += (char)M.y; return output; public point DCodePoint(Dictionary<int, point> t) point Z = chen(t3, k); point m; m.x = t4.x * getX_1(Z.x, p) % p; m.y = t4.y * getX_1(Z.y, p) % p; return m; public string ECode(string input) /明文的輸入是一個string類型,但是單個的操作應(yīng)該是對單個的字符char轉(zhuǎn)
8、換成的int類型進行計算 string output = "" point M; Dictionary<int, point> C = new Dictionary<int, point>(); for (int i = 0; i < input.Length; i+) M.x = i; M.y = inputi; C = ECodePoint(M); output += (char)C1.x; output += (char)C1.y; output += (char)C2.x; output += (char)C2.y; return ou
9、tput; public Dictionary<int, point> ECodePoint(point m) point c1 = new point(); point c2 = new point(); c1 = chen(A, r); point Y = chen(B, r); c2.x = Y.x * m.x % p; c2.y = Y.y * m.y % p; Dictionary<int, point> EE = new Dictionary<int, point>(); EE.Add(1, c1); EE.Add(2, c2); return
10、EE; class Program static void Main(string args) Class1 EE = new Class1(); string S = "" /加密簡單,隨便輸入點東西就可以加密了,但是解密不行啊,隨便輸入肯定是錯誤的結(jié)果, /程序肯定會出錯,所以,只支持對之前加密的結(jié)果進行解密。 / Console.WriteLine("使用在素域上的曲線 y2 = x3 + 5*x +37 ,使用Menezes-Vanstone
11、的算法:"); /Console.WriteLine("在素域p=127上,私鑰為k=9,公鑰A(11,4),B(120,41),對明文字符串直接轉(zhuǎn)換為int進行加密"); Console.WriteLine("請輸入加密的內(nèi)容"); S = Console.ReadLine(); Console.WriteLine("密文如下"); S = EE.ECode(S); Console.WriteLine(S); Console.WriteLine("完成"); / Console.WriteLine(&q
12、uot;對之前密文解密,得到明文如下(由于輸入密文不正確絕對會使這個程序出錯,所以只能解密絕對安全的密文):"); S = EE.DCode(S); Console.WriteLine(S); Console.WriteLine("完成"); #region XMl異常符號解決 / <summary> / 把一個字符串中的 低序位 ASCII 字符 替換成 &#x 字符 / 轉(zhuǎn)換 ASCII 0 - 8 -> - / 轉(zhuǎn)換 ASCII 11 - 12 -> - / 轉(zhuǎn)換 ASCII 14 - 31 -> - / </su
13、mmary> / <param name="tmp"></param> / <returns></returns> public static string ReplaceLowOrderASCIICharacters(string tmp) StringBuilder info = new StringBuilder(); foreach (char cc in tmp) int ss = (int)cc; if (ss >= 0) && (ss <= 8) | (ss >= 11)
14、&& (ss <= 12) | (ss >= 14) && (ss <= 32) info.AppendFormat("�:X;", ss); else info.Append(cc); return info.ToString(); / <summary> / 把一個字符串中的下列字符替換成 低序位 ASCII 字符 / 轉(zhuǎn)換 - -> ASCII 0 - 8 / 轉(zhuǎn)換 - -> ASCII 11 - 12 / 轉(zhuǎn)換 - -> ASCII 14 - 31 / </summa
15、ry> / <param name="input"></param> / <returns></returns> public static string GetLowOrderASCIICharacters(string input) if (string.IsNullOrEmpty(input) return string.Empty; int pos, startIndex = 0, len = input.Length; if (len <= 4) return input; StringBuilder r
16、esult = new StringBuilder(); while (pos = input.IndexOf("&#x", startIndex) >= 0) bool needReplace = false; string rOldV = string.Empty, rNewV = string.Empty; int le = (len - pos < 6) ? len - pos : 6; int p = input.IndexOf("", pos, le); if (p >= 0) rOldV = input.Subst
17、ring(pos, p - pos + 1); / 計算 對應(yīng)的低位字符 short ss; if (short.TryParse(rOldV.Substring(3, p - pos - 3), NumberStyles.AllowHexSpecifier, null, out ss) if (ss >= 0) && (ss <= 8) | (ss >= 11) && (ss <= 12) | (ss >= 14) && (ss <= 32) needReplace = true; rNewV = Convert.ToChar(ss).ToString(); pos = p + 1
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 房地產(chǎn)企業(yè)財務(wù)戰(zhàn)略研究與實施
- 醫(yī)?;饘艄芾磙k法
- 銷售團隊激勵機制探索與實踐
- 河南財務(wù)票據(jù)管理辦法
- 景區(qū)植被養(yǎng)護管理辦法
- 利用改進的蜣螂優(yōu)化算法結(jié)合深度學(xué)習(xí)技術(shù)進行高壓斷路器故障診斷的研究
- 服務(wù)設(shè)計思維在茶飲體驗系統(tǒng)中的應(yīng)用研究
- 體育機構(gòu)薪酬管理辦法
- 高壓電力系統(tǒng)保護技術(shù)研究
- 江西房產(chǎn)抵押管理辦法
- 淹溺診療規(guī)范內(nèi)科學(xué)診療規(guī)范診療指南2023版
- PremiereProCC視頻剪輯基礎(chǔ)教程PPT完整版全套教學(xué)課件
- 新教材北師大版高中英語選擇性必修第一冊全冊各單元學(xué)案(單詞短語句型寫作等知識點匯總)
- 鍍鋅板國家新標準規(guī)定
- 《電工學(xué)》“課程思政”教學(xué)設(shè)計案例
- 數(shù)字時代的商務(wù)英語寫作知到章節(jié)答案智慧樹2023年對外經(jīng)濟貿(mào)易大學(xué)
- 檢驗科溝通技巧及其它
- 2022年安徽大學(xué)科研助理(校聘)招聘60人筆試備考題庫及答案解析
- 四年級閱讀訓(xùn)練概括文章主要內(nèi)容(完美)
- YY/T 0995-2015人類輔助生殖技術(shù)用醫(yī)療器械術(shù)語和定義
- GB/T 19352.1-2003熱噴涂熱噴涂結(jié)構(gòu)的質(zhì)量要求第1部分:選擇和使用指南
評論
0/150
提交評論