試圖創建一個簡單的替換密碼,我的程序工作得很好,但它的數據不加密或解密。我真的不知道我應該添加到我的代碼,以便它能正常工作...任何想法? 這是我的代碼使用簡單的替換密碼進行加密和解密
namespace yaba
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnEncrypt_Click(object sender, EventArgs e)
{
string encrypt = tboxIO.Text;
encrypt.ToLower();
bool tbNull = tboxIO.Text == "";
if (tbNull)
MessageBox.Show("There is nothing to encrypt.");
else
{
char[] array = encrypt.ToCharArray();
for (int i = 0; i < array.Length; i++)
{
int num = (int)array[i];
if (num >= 'a' && num <= 'z')
{
num += Convert.ToInt32(tbShift.Text);
if (num > 'z')
{
num = num - 26;
}
}
else if (num >= 'A' && num <= 'Z')
{
num += Convert.ToInt32(tbShift.Text);
if (num > 'Z')
{
num = num - 26;
}
}
array[i] = (char)num;
}
lblIO.Text = "Encrypted Message";
tboxIO.Text = new string(array).ToLower();
}
tboxIO.Copy();
}
private void btnDecrypt_Click(object sender, EventArgs e)
{
string decrypt = tboxIO.Text;
decrypt.ToLower();
bool tbNull = tboxIO.Text == "";
if (tbNull)
MessageBox.Show("There is nothing to decrypt.");
else
{
char[] array = decrypt.ToCharArray();
for (int i = 0; i < array.Length; i++)
{
int num = (int)array[i];
if (num >= 'a' && num <= 'z')
{
num -= Convert.ToInt32(tbShift.Text);
if (num > 'z')
num = num - 26;
if (num < 'a')
num = num + 26;
}
else if (num >= 'A' && num <= 'Z')
{
num -= Convert.ToInt32(tbShift.Text);
if (num > 'Z')
num = num - 26;
if (num < 'A')
num = num + 26;
}
array[i] = (char)num;
}
lblIO.Text = "Decrypted Message";
tboxIO.Text = new string(array).ToUpper();
}
tboxIO.Copy();
}
private void pictureBox1_Click(object sender, EventArgs e)
{
MessageBox.Show("hehe");
}
private void tboxIO_MouseClick(object sender, MouseEventArgs e)
{
tboxIO.SelectAll();
tboxIO.Copy();
}
private void tbShift_MouseClick(object sender, MouseEventArgs e)
{
tbShift.SelectAll();
}
private void label1_Click(object sender, EventArgs e)
{
}
}
}