private void DecryptCipher(object sender, RoutedEventArgs e) { string buffer = ""; if (String.IsNullOrWhiteSpace(CessarTextBox1.Text)) { return; } if (String.IsNullOrWhiteSpace(CessarTextBox2.Text)) { return; } if (String.IsNullOrWhiteSpace(AchipherBox.Text)) { return; } FileInfo file = new FileInfo(CessarTextBox1.Text); if (file.Exists) { using (FileStream fileStream = File.OpenRead(CessarTextBox1.Text)) { byte[] array = new byte[fileStream.Length]; fileStream.Read(array, 0, array.Length); string text = System.Text.Encoding.Default.GetString(array); int key = Int32.Parse(AchipherBox.Text); buffer = Cessar.CessarDecrypt(text, key); } using (FileStream fileStream = new FileStream(CessarTextBox2.Text, FileMode.OpenOrCreate)) { byte[] array = Encoding.Default.GetBytes(buffer); fileStream.Write(array, 0, array.Length); } } else { CessarTextBox1.Text = "File is not exist"; } CessarTextBox1.Text = ""; CessarTextBox2.Text = ""; }
private void CessarStart(object sender, RoutedEventArgs e) { string buffer = ""; if (String.IsNullOrWhiteSpace(CessarTextBox1.Text)) { return; } if (String.IsNullOrWhiteSpace(CessarTextBox2.Text)) { return; } if (String.IsNullOrWhiteSpace(AchipherBox.Text)) { return; } using (FileStream fileStream = File.OpenRead(CessarTextBox1.Text)) { byte[] array = new byte[fileStream.Length]; fileStream.Read(array, 0, array.Length); string cipher = System.Text.Encoding.Default.GetString(array); int key = Int32.Parse(AchipherBox.Text); buffer = Cessar.CessarEncrypt(cipher, key); } using (FileStream fileStream = new FileStream(CessarTextBox2.Text, FileMode.OpenOrCreate)) { byte[] array = Encoding.Default.GetBytes(buffer); fileStream.Write(array, 0, array.Length); } CessarTextBox1.Text = ""; CessarTextBox2.Text = ""; }