private void button1_Click(object sender, EventArgs e) { if (isMatch) { try { RCC5 encoder = new RCC5(Encoding.ASCII.GetBytes(textBox1.Text)); string[] file = File.ReadAllLines(path); string[] newfile = new string[file.Length + 1]; newfile[0] = Path.GetFileName(path); for (int i = 1; i < newfile.Length; i++) { newfile[i] = file[i - 1]; } string temppath = Path.GetDirectoryName(path) + "\\" + Path.GetFileNameWithoutExtension(path) + ".scram"; File.AppendAllLines(temppath, newfile); FileStream read = File.OpenRead(temppath); byte[] dfile = new byte[read.Length]; read.Read(dfile, 0, dfile.Length); read.Close(); File.Delete(temppath); byte[] efile = encoder.Encode(dfile); FileStream save = File.Create(temppath); save.Write(efile, 0, efile.Length); save.Close(); MessageBox.Show("Файл зашифрован и сохранён по пути: \"" + temppath + "\""); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void button1_Click(object sender, EventArgs e) { try { RCC5 decoder = new RCC5(Encoding.ASCII.GetBytes(textBox1.Text)); FileStream openfile = File.OpenRead(path); byte[] efile = new byte[openfile.Length]; openfile.Read(efile, 0, efile.Length); openfile.Close(); byte[] dfile = decoder.Decode(efile); string temppath = Path.GetDirectoryName(path) + "\\" + Path.GetFileNameWithoutExtension(path) + "d" + Path.GetExtension(path); File.WriteAllBytes(temppath, dfile); string[] lines = File.ReadAllLines(temppath); File.Delete(temppath); string[] newfile = new string[lines.Length - 1]; string name = lines[0]; for (int i = 1; i < newfile.Length; i++) { newfile[i - 1] = lines[i]; } File.WriteAllLines(Path.GetDirectoryName(path) + "\\" + name, newfile); MessageBox.Show("Файл расшифрован и сохранён по пути: \"" + Path.GetDirectoryName(path) + "\\" + name + "\"", "Готово", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }