📄 form1.cs
字号:
using System;
using System.Windows.Forms;
using System.IO;
namespace Festel
{
public partial class Festel : Form
{
//================================================================
// Ten file nhap va xuat
//================================================================
public string inName, outName;
public byte[] buffKey;
public Festel()
{
InitializeComponent();
}
//================================================================
// Thu hien mo file
//================================================================
private void btnOpen_Click(object sender, EventArgs e)
{
openFile();
inName = InFileName.Text;
}
//================================================================
// Ham mo file tu hop thoai --> tra ve ten file
//================================================================
private void openFile()
{
openFileDialog.Title = "Open Data File";
openFileDialog.Filter = "All|*.*";
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
InFileName.Text = openFileDialog.FileName;
}
}
//================================================================
//Ma hoa theo tung thuat toan khac nhau,phu thuoc vao lua chon o radioButton
//================================================================
private void btnEncode_Click(object sender, EventArgs e)
{
int flag=0;
if (radFestel.Checked == true)
flag = 0;
else
{
if (radFestel_Type1.Checked == true)
flag = 1;
else
{
if (radFestel_Type2.Checked == true)
flag = 2;
else
if (radFestel_Type3.Checked == true)
flag = 3;
}
}
try
{
FestelAlg.v = Convert.ToUInt64(toolStripKey.Text);
if (InFileName.Text == "")
{
MessageBox.Show("Let's Open file");
return;
}
if (OutFileName.Text == "")
{
MessageBox.Show("Let's read out put file name");
}
inName = InFileName.Text;
outName = OutFileName.Text;
ProcessFile.Encode(inName,outName,flag);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
//================================================================
// Read key from file
//================================================================
private void toolStripButton1_Click(object sender, EventArgs e)
{
ReadKey();
}
// Get key random
private void toolStripButton2_Click(object sender, EventArgs e)
{
GetKey();
}
//
public void GetKey()
{
Random rd = new Random();
buffKey = new byte[8];
rd.NextBytes(buffKey);
FestelAlg.v = BitConverter.ToUInt64(buffKey, 0);
toolStripKey.Text = FestelAlg.v.ToString();
FileStream fs = new FileStream("key.key", FileMode.Create);
fs.Write(buffKey, 0, 8);
fs.Close();
}
//
public void ReadKey()
{
openFileDialog.Title = "Open key File";
openFileDialog.Filter = "Key File|*.key";
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
string fn = openFileDialog.FileName;
byte[] buffKey = new byte[8];
FileStream fs = new FileStream(fn, FileMode.Open);
fs.Read(buffKey, 0, 8);
ulong l = BitConverter.ToUInt64(buffKey, 0);
FestelAlg.v = l;
toolStripKey.Text = Convert.ToString(l);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -