public void writeText(string emri, string mesazhi,string path,string token) { faza3 f3 = new faza3(); if (f3.status(token) == "Nuk ekziston") { Console.WriteLine(" Tokeni nuk ekziston "); } else { string[] tokench = token.Split(); DES DESalg = DES.Create(); byte[] keyb = new byte[8]; byte[] ivb = new byte[8]; keyb = DESalg.Key; ivb = DESalg.IV; Random rand = new Random(); string KEY = Convert.ToBase64String(keyb); string IV = Convert.ToBase64String(ivb); string enctext = encrypt(emri, mesazhi, KEY, IV); string filere = File.ReadAllText("C:/Users/hp/Desktop/keys/users.txt"); string[] a = filere.Split(); string h = ""; for (int i = 0; i < a.Length; i++) { if (tokench[0] == a[i]) { h = a[i - 1]; } } RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(2048); var privatekey = File.ReadAllText("C:/Users/hp/Desktop/keys/" + h + "pri.xml"); rsa.FromXmlString(privatekey); byte[] msgb = Encoding.ASCII.GetBytes(arg[3]); string[] arg = enctext.Split(); string filepath = "C:/Users/hp/Desktop/keys/users.txt"; arg[0] = arg[0] + " "; File.AppendAllText(filepath, arg[0]); string encr = enctext + " " + Convert.ToBase64String(rsa.Encrypt(msgb, true)) + " " + tokench[0]; if (String.IsNullOrEmpty(path)) { Console.WriteLine("Encrypted ...: " + encr); } else { File.WriteAllText(path + emri + "encrypted.xml", encr) Console.WriteLine(" Teksti u ruajt ne : C:/Users/hp/Desktop/keys/ "); } string filepath = "C:/Users/hp/Desktop/keys/users.txt"; emri = emri + " "; File.AppendAllText(filepath, emri); arg[0] = arg[0] + " "; File.AppendAllText(filepath, arg[0]); }
static void Main(string[] args) { count numero = new count(); morse morseC = new morse(); caesar caesarC = new caesar(); rsa rsa = new rsa(); faza3 f3= new faza3(); if (args[0] == "1") { Environment.Exit(-1); } else if (args[1] == "2") { if (args[2] == "1") { Console.WriteLine("numri i charactereve : " + numero.countCh(args[0])); } else if (args[2] == "2") { Console.WriteLine("numri i rreshtave : " + numero.countLi(args[0])); } else if (args[2] == "3") { Console.WriteLine("numri i fjaleve : " + numero.countW(args[0])); } else if (args[2] == "4") { Console.WriteLine("numri i fjalive : " + numero.countWo(args[0])); } else if (args[2] == "5") { Console.WriteLine("numri i zanoreve : " + numero.countZan(args[0])); } else if (args[2] == "6") { Console.WriteLine("numri i bashtingelloreve : " + numero.countBash(args[0])); } else if(args[2]=="7") {Console.WriteLine("numri i simboleve : " + numero.countSymb(args[0]));} else { Console.WriteLine("Wrong input !!!"); } } else if (args[1] == "3") { char[] ar = args[0].ToCharArray(); string emri = "", VP = ""; if (args[2] == "1") { for (int i = 0; i < ar.Length; i++) { emri = emri + morseC.morseEnco(ar[i]);//encode if (ar[i] == ' ') { } else { Console.Beep(); } Console.Write(morseC.morseEnco(ar[i])); } Console.WriteLine("\n"); } else if (args[2] == "2") { for (int i = 0; i < ar.Length; i++)//decode { VP = VP + ar[i]; if (ar[i] == ' ') { emri = emri + morseC.morseDeco(VP); VP = ""; } } Console.WriteLine(emri); } else { Console.WriteLine("Wrong input !!!"); } } else if (args[1] == "4") { if (args[2] == "1") { int k = Convert.ToInt32(args[3]); Console.WriteLine("ciphertext : " + caesarC.caesarCipherEnco(args[0], k)); } else if (args[2] == "2") { int k = Convert.ToInt32(args[3]); Console.WriteLine("plaintext : " + caesarC.caesarCipherDeco(args[0], k)); } else if(args[2]=="3") {caesarC.bruteForce(args[0]);} else { Console.WriteLine("Wrong input !!!"); } } else if (args[0] == "create-user") { rsa.createUser(args[1]); } else if (args[0] == "delete-user") { rsa.deleteUser(args[1]); } else if (args[0] == "import-key") { rsa.importKey(args[1], args[2]); } else if (args[0] == "export-key") { rsa.exportKey(args[1], args[2]); } else if (args[0] == "write-text") { rsa.writeText(args[1], args[2],args[3],args[4]); } else if (args[0] == "read-text") { rsa.readText(args[1],args[2]); } else if (args[0] == "login") { f3.Login(args[1]); } else if (args[0] == "status") { Console.WriteLine(f3.status(args[1])); } else { Console.WriteLine("Wrong input !!!"); } Console.ReadKey(); }
public void readText(string mesazhi, string token) { faza3 f3=new faza3(); if (String.IsNullOrEmpty(token)) { string[] msg = mesazhi.Split(); string m = msg[0] + " " + msg[1] + " " + msg[2] + " " + msg[3]; //string t = Console.ReadLine();//File.ReadAllText("C:/Users/hp/Desktop/keys/"+ emri +"encrypted.xml"); string dec = decrypt(m); string[] arg = dec.Split(); Console.WriteLine(" Emri ..:" + arg[0]); Console.WriteLine(" Decrypted ..:" + arg[1]); } else { string[] msg = mesazhi.Split(); rsa rsa = new rsa(); string m = msg[0] + " " + msg[1] + " " + msg[2] + " " + msg[3]; string dec = decrypt(m); string[] arg = dec.Split(); string filere = File.ReadAllText("C:/Users/hp/Desktop/keys/users.txt");// string[] a = filere.Split(); string h = ""; if(f3.status(token)=="Nuk ekziston") { Console.Write(" Tokeni jo valid "); return; } string[] tokenich = token.Split(); string derguesi = ""; for (int i = 0; i < a.Length; i++) { if (tokenich[0] == a[i]) { derguesi = a[i - 1]; } } string k = rsa.RSAdecr(derguesi, msg[4]); string s = m + " " + k; string desdcr = decrypt(s); string[] dcr = desdcr.Split(); Console.WriteLine(" Emri i marresit ..:" + arg[0]); Console.WriteLine(" Decrypted ..:" + arg[1]); Console.WriteLine(" Emri i derguesit ..:" + derguesi);//Encoding.ASCII.GetString(Convert.FromBase64String(derguesi))); if (arg[1] == dcr[1]) { Console.WriteLine(" Nenshkrimi ..: valid"); } else { Console.WriteLine(" Nenshkrimi ..: jovalid , mungon celesi publik" + derguesi); } File.WriteAllText("C:/Users/hp/Desktop/keys/" + arg[0] + "decrypted.xml", dec); Console.WriteLine("teksti u ruajt ne ...:" + "C:/Users/hp/Desktop/keys/"); }