试图创建一个简单的替换密码,我的程序工作得很好,但它没有加密或解密数字。我真的不知道我应该在我的代码中添加什么以便它正常工作......任何想法?这是我的代码
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)
{
}
}
}