我刚刚学习了一些有关密码学的基础知识,想试试其中一种方法,叫做锯齿置换。
这种方法的作用是将整个句子组合起来,并从零开始给它们编号。然后,将偶数索引字符分成一个数组,将奇数索引字符分成另一个数组。
当我将这两个数组转换为字符串并放入文本框中时,只有第一个字符串显示出来。
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;
}