我正在写一个字符串“123124125”转换为这样的长度为3的整数数组的程序:如何将字符串数字转换为int然后char?
int[0] = 123
int[1] = 124
int[2] = 125
假设密文字符串有123124125.
我用:
int number[100];
int length1 = ciphertext-> Length;
int count = 0;
int count1 = 0;
char w[100];
while (count1 < length1)
{
number[count] = (ciphertext[count1] * 100) + (ciphertext[count1 + 1] * 10) + ciphertext[count1 + 2];
count++;
count1 = count1 + 3;
}
然后我想用这个公式来解密它并直接转换成字符串:
for (int i = 0; i < sizeof(number); i++)
{
String^demessage += Convert::ToChar(number[i]^(int(key) * 2 + int(key)/int(key)) % 255);
}
但它显示了以下结果:
5553195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195195 -................................ .... 1849664615
我哪里错了? 我是否需要先将int转换为char,然后继续执行公式?
谢谢。非常感谢您的帮助。
我认为你得到的数字是你想要的字符的数字表示。我对API不熟悉,但我会做一些非常简单的事情,例如确认添加Convert :: ToChar(65)会产生预期的'a'字符。如果你没有正确使用,你将无法调试其他任何东西。 – cyborg
我可能发现了这个问题,可能是这个公式: number [count] =(ciphertext [count1] * 100)+(ciphertext [count1 + 1] * 10)+ ciphertext [count1 + 2]; count ++; 字符串“123124125”,通过使用上面的公式,它不能得到int [0] = 123,int [1] = 124 int [2] = 125, 和我出来很多方式仍然无法工作,有人可以帮忙吗? –