static async Task RunAsync() { KeyPair keyPair = keyManager.CreateKeys(); using PublicKey publicKey = keyPair.publicKey; using SecretKey secretKey = keyPair.secretKey; String FileName = ""; String applicationName = "Machine Learning with Encryption"; String version = "Prototype v 1.0.0"; Console.Write(new String('-', Console.WindowWidth)); Console.SetCursorPosition((Console.WindowWidth - applicationName.Length) / 2, Console.CursorTop); Console.WriteLine(applicationName); Console.SetCursorPosition((Console.WindowWidth - "______".Length) / 2, Console.CursorTop); Console.WriteLine("______"); Console.SetCursorPosition((Console.WindowWidth - "/ __ \\".Length) / 2, Console.CursorTop); Console.WriteLine("/ __ \\"); Console.SetCursorPosition((Console.WindowWidth - "_|_|__|_|_".Length) / 2, Console.CursorTop); Console.WriteLine("_|_|__|_|_"); Console.SetCursorPosition((Console.WindowWidth - "| |".Length) / 2, Console.CursorTop); Console.WriteLine("| |"); Console.SetCursorPosition((Console.WindowWidth - "| M.L.E. |".Length) / 2, Console.CursorTop); Console.WriteLine("| M.L.E. |"); Console.SetCursorPosition((Console.WindowWidth - "|__________|".Length) / 2, Console.CursorTop); Console.WriteLine("|__________|"); Console.Write(new String('-', Console.WindowWidth)); Console.WriteLine(version + "\n"); try { Console.Write("\tEnter the name of the CSV containing the samples to be encrypted: "); FileName = Console.ReadLine(); string fileExtension = Path.GetExtension(FileName); if (fileExtension != ".csv") { Console.WriteLine("file type must be CSV"); return; } string filePath = Path.GetFullPath(Directory.GetCurrentDirectory()) + "\\" + FileName; if (!File.Exists(filePath)) { throw new Exception("File " + filePath + " does not exists."); } List <List <float> > featureList = Logics.EncryptedMLHelper.ReadValuesToList(filePath); List <List <Ciphertext> > encryptedFeatureValues = Logics.EncryptedMLHelper.encryptValues(featureList, publicKey, contextManager.Context); client.BaseAddress = new Uri("https://mle.isot.ca/"); client.DefaultRequestHeaders.Accept.Clear(); Query query = new Query { publicKey = publicKey, encryptedFeatureValues = encryptedFeatureValues }; Console.WriteLine("\tSending Query..."); List <List <Ciphertext> > encryptedWeightedSums = await getPredictions(query); var results = Logics.EncryptedMLHelper.decryptValues(encryptedWeightedSums, secretKey, contextManager.Context); var csv = new StringBuilder(); using (System.IO.StreamWriter file = new System.IO.StreamWriter("Result.csv")){ foreach (var sample in results) { for (int i = 0; i < (sample.Count - 1); i++) { file.Write(sample[i].ToString() + ","); } file.Write(sample[sample.Count - 1].ToString() + "\n"); } } Console.WriteLine("\n\tSuccess, Results saved to Results.csv.\n"); } catch (Exception e) { Console.WriteLine("\n\tError:"); Console.WriteLine("\t" + e.Message); if (e.InnerException != null) { Console.WriteLine("\t\t" + e.InnerException.Message); } Console.WriteLine("\n"); } }