public string GetMessage(Cypher c) { BigInteger eid = GeneralFunctions.Pair(d_id, c.U, k, p); char[] msg = c.V.ToCharArray(); char[] m = new char[msg.Length]; char[] hash = GeneralFunctions.H2hash(eid, p).ToCharArray(); for (int i = 0; i < msg.Length; i++) { m[i] = (char)(msg[i] ^ hash[i % hash.Length]); } string message = new String(m); return message; }
private static void Main(string[] args) { string id = "*****@*****.**"; string poruka = "moram porati posluku"; Cypher sifrat; if (args.Length < 2) { test(); Console.WriteLine("\n"); upute(); return; } // namjesti postavke prvo Setup setup = new Setup(); if (args[0] == "-f") { string put = args[1]; if (!File.Exists(put)) { poruka = File.ReadAllText(put); if (args.Length != 3) { upute(); return; } id = args[args.Length - 1]; encode(poruka, id, setup); } else { Console.WriteLine("File does not exists!\n"); upute(); return; } } string sif; string xs; string ys; if (args[1] == "-d") { if (args[1] == "-f" && args.Length == 6) { string put = args[2]; sif = File.ReadAllText(put); id = args[args.Length - 1]; xs = args[3]; ys = args[4]; } else if (args.Length > 6 || args.Length != 5) { upute(); return; } else { sif = args[1]; xs = args[2]; ys = args[3]; id = args[args.Length - 1]; } BigInteger x1 = new BigInteger(xs, 10); BigInteger y1 = new BigInteger(ys, 10); FpFieldElement x = (FpFieldElement)setup.E.FromBigInteger(x1); FpFieldElement y = (FpFieldElement)setup.E.FromBigInteger(y1); FpPoint point = new FpPoint(setup.E, x, y); sifrat = new Cypher { U = point, V = sif }; decode(sifrat, id, setup); } else { poruka = ""; for (int i = 1; i < args.Length - 2; i++) { poruka += args[i] + " "; } poruka += args[args.Length - 2]; id = args[args.Length - 1]; encode(poruka, id, setup); } Console.ReadKey(); }
private static void decode(Cypher cypher, string id, Setup setup) { // tajni ključ FpPoint d_id = setup.Exctract(id, true); Decrypt d = new Decrypt(d_id, setup.p, setup.k); string msg = d.GetMessage(cypher); Console.Out.WriteLine("decoded: \"" + msg + "\""); }