我一直在学习密码学的基础知识,我想给
其中一种叫做zigzag transposition的方法可以试试。
这个方法所做的就是组合整个句子并给它们从零开始的索引。
然后它将偶数索引字符分隔到一个数组中,将奇数字符分隔到另一个数组中。
当我将两个数组转换为字符串然后将它们放在文本框中时,只显示第一个字符串。
private void ZigzagBu_Click(object sender, EventArgs e) {
string s = PlaintextTB.Text;
s = s.Replace(" ","");
char[] whole = s.ToCharArray();
char[] even = new char[whole.Length];
char[] odd = new char[whole.Length];
int evenIndex = 0;
int oddIndex = 0;
for(int i =0;i<whole.Length;i++) {
if (i % 2 == 0) {
even[evenIndex] = whole[i];
evenIndex++;
}
else {
odd[oddIndex] = whole[i];
oddIndex++;
}
}
s = new String(even);
string m = new String(odd);
CiphertextTB.Text = s+m;
}
最佳答案
问题在于 char 数组的大小。我通过 <br/>
解决了它
char[] even = new char[whole.Length/2];
char[] odd = new char[whole.Length/2];
关于c# - 将两个字符串连接到一个文本框中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47323564/