C#程序,用一个文本框和一个按钮实现ROT13的解密和加密。(题目给的要求是先定义一个ROT13函数)
// ROT13 加密/解密函数
string Rot13(string input)
{
StringBuilder output = new StringBuilder(input.Length);
foreach (char c in input)
{
if (Char.IsLetter(c))
{
char d = Char.IsUpper(c) ? 'A' : 'a';
output.Append((char)(((c + 13) - d) % 26 + d));
}
else
{
output.Append(c);
}
}
return output.ToString();
}
// 在按钮单击事件中调用 Rot13() 函数
private void button1_Click(object sender, EventArgs e)
{
textBox2.Text = Rot13(textBox1.Text);
}
```