単純な置換暗号を作成しようとすると、私のプログラムは問題なく動作しますが、数値の暗号化または復号化は行われません。コードが適切に機能するように、コードに何を追加すればよいか本当にわかりません...何かアイデアはありますか??? これは私のコードです
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)
{
}
}
}