L.A*_*ham 1 c# string encryption
我正在开发一个使用位置交换对文本进行加密的项目。我已经使用字符位置交换 { Hello -> elloH} 完成了该项目,现在我正在研究位位置交换。我使用相同的算法来加密这些位,但问题是如何将结果位改回字符串?
注意:不能使用BitArray。
这是我现在所拥有的:
static byte[] toByteArray(string s)
{
byte[] arr = new System.Text.UTF8Encoding(true).GetBytes(s);
return arr;
}// Byte Array must be changed to bits.
private void button1_Click(object sender, EventArgs e)
{
String[] X = new String[x.Length];// Will Contain the Encoded Bits
for(int i=0;i<x.Length;i++)
{
X[i] = Convert.ToString(x[i], 2);
textBox3.Text += X[i];
}
}
Run Code Online (Sandbox Code Playgroud)
string str = "1000111"; //this is your string in bits
byte[] bytes = new byte[str.Length / 7];
int j = 0;
while (str.Length > 0)
{
var result = Convert.ToByte(str.Substring(0, 7), 2);
bytes[j++] = result;
if (str.Length >= 7)
str = str.Substring(7);
}
var resultString = Encoding.UTF8.GetString(bytes);
Run Code Online (Sandbox Code Playgroud)