printf在屏幕上显示“ -858993460”。或“╠╠╠╠╠╠╠╠”;这些是什么? [英] printf displays "-858993460" or "╠╠╠╠╠╠╠╠"; what are these?
问题描述
我正在尝试构建一个对密码进行加密的程序,然后执行相反的过程(从已加密的密码中读出正确的密码)。
I am trying to build a program that encrypts a password and then does the reverse process (tells a correct password from an encrypted one).
为此,我有:
-
密码(
char []
类型);
具有以下特征的加密密钥( vector - int []
类型)与密码的 char
相同的长度;
an encryption key (vector - int[]
type) that has the same length as the char
of the password;
两步(也放置在 int step [2]类型的 vector 中) $ c>)。
two steps (placed also in a vector of type int step[2]
).
要求是必须使用以下两个步骤来构建加密过程:
The requirement is that the encryption process has to be built using these two steps:
- 第一个(<< c $ c> step [0] 中的值)用于添加从密码
char
的第一个位置到加密密钥 vector 的第一个位置开始的值(ASCII),其步长等于第一步step [0]
;
- the first one (the value in
step[0]
) is used to add the value (ASCII) starting from the first position of the passwordchar
to the first position of the encryption key vector for a number of steps equal to the first stepstep[0]
;
例如,添加 char密码[0]
到 int键[0]
,然后添加 char密码[1]
到 int键[1]
,依此类推,其步数等于 step [0]中的值
。
for example, adds char password[0]
to int key[0]
, then adds char password[1]
to int key[1]
and so on for a number of steps equal to the value placed in step[0]
.
- 第二个(
step [1]
)从密码char
的ASCII值的相应位置中减去加密密码的值s等于第二步(step [1]
)。
- the second one (
step[1]
) subtracts from the corresponding position of the ASCII value of the passwordchar
, the value of the encryption key for a number of steps equal to the second step (step[1]
).
例如,从 int键[5]
减去 char密码[5]
,然后减去 char
,依此类推,其步骤数等于 int键[6]
中的密码[6] 中的值步骤[1]
。
for example, subtracts char password[5]
from int key[5]
, then subtracts char password[6]
from int key[6]
and so on for a number of steps equal to the value placed in step[1]
.
然后重复该过程,直到密码字符的长度结束
And then, the process repeats until the end of the length of the password char.
我建立了一个下面的函数,应该这样做(将多个步骤相加,然后将多个其他步骤相减,然后重复该过程,直到密码char的末尾-加密密钥向量的长度与密码char相同。)
I built a function as below that should do this (addition for a number of steps, then subtraction for a number of other steps, and repetition of the process until the end of the password char - the encryption key vector has the same length as the password char).
结果被放置在新的向量中(用于加密)或新的 char
(用于反向查找密码)。
The result is placed in a new vector (for encryption) or in a new char
(for the reverse process of finding the password).
void criptareFinal(char password4[255],
int longKey1[255],
int b4,
int step2[2]) {
int encryptedPass[255];
int a = step2[0],
b = step2[1],
n = b4,
i,
ap = a,
bp = b;
for (i = 0; i < n; i++) {
if (ap > 0) {
encryptedPass[i] = longKey1[i] + password4[i];
ap--;
}
else if (bp > 0) {
encryptedPass[i] = longKey1[i] - password4[i];
bp--;
}
else if (ap == 0 && bp == 0) {
ap = a;
bp = b;
}
}
int i1;
printf("\n");
for (i1 = 0; i1 < b4; i1++)
printf("%d ", encryptedPass[i1]);
}
然后,如果我尝试 printf
矢量(用于加密过程),以显示矢量的内容,出现类似以下消息:
Then if I try to printf
the vector (for encryption process) in order to show the content of the vector, a message similar to this one appears:
1090 923 916 1151 942 913 962 998 960 936 962 917 -858993460 -858993460 -858993460 -858993460 -858993460 -858993460 -858993460 -858993460
为什么显示 -858993460?
此外,如果尝试 printf
char
以相反的方式显示密码(将加密的密码可读的代码)
Also, if a try to printf
the char
for showing the password in the reverse process (form an encrypted password to a readable one) using the following code,
void decriptareFinal(int encryptedPass5[255],
int longKey2[255],
int b5,
int steps3[2]) {
char Password1[255];
int a = steps3[0],
b = steps3[1],
n = b5,
i2,
ap = a,
bp = b;
for (i2 = 0; i2 < n; i2++) {
if (ap > 0) {
Password1[i2] = encryptedPass5[i2] - longKey2[i2];
ap--;
}
else if (bp > 0) {
Password1[i2] = longKey2[i2] - encryptedPass5[i2];
bp--;
}
else if (ap == 0 && bp == 0) {
ap = a;
bp = b;
}
}
int j2;
printf("\n");
for (j2 = 0; j2 < b5; j2++)
printf("%c", Password1[j2]);
}
然后出现此消息:
côő~ypaXOF╠╠╠╠╠╠╠╠
什么是╠?
此╠╠╠╠╠╠╠╠显示不正确(其余的côő〜ypaXOF是正确的。)
也。我尝试在字符串/向量的末尾添加手动形式 [0]
,如果这样做,则不会出现类型错误消息 -858993460
或╠╠╠╠╠╠╠╠
类型出现。
它工作正常,并且告诉我 char
(密码)或 int
(键)是正确的。
Also. I tried to add and subtract manually form [0]
to the end of the string/vector and if I do that, no error message of type -858993460
or of type ╠╠╠╠╠╠╠╠
appears.
It works fine and that tells me that the values in the char
(password) or int
(key) are correct.
如果很重要,我可以在 Windows 64bit 上工作,但是我会使用 Visual Studio 。
另外,我有一台 Mac 。那里我有同样的问题,但是我得到了 -858993460
或╠╠╠╠╠╠╠╠
消息(例如 0
而不是 -858993460
)。
If it is of importance, I work on Windows 64bit, but I use Visual Studio.
Also, I have a Mac. There I have the same problem, but instead of -858993460
or ╠╠╠╠╠╠╠╠
I get other messages (for instance 0
instead of -858993460
).
推荐答案
尤其是Arkku,谢谢大家的回答。
很有帮助。
我修复了它,现在工作正常。
我在 else if(ap == 0&& bp == 0)之后的最后一个条件中添加了 i = i-1,以便在同一位置进行迭代。
Thank you all for the answers, esspecially to Arkku. That helped a lot. I fixed it and now it works fine. I added "i = i - 1" at the last condition, after "else if (ap == 0 && bp == 0)" in order to mantain the iteration on the same position.
这就是我所做的:
for (i2 = 0; i2 < n; i2++) {
if (ap > 0) {
Password1[i2] = encryptedPass5[i2] - longKey2[i2];
ap--;
}
else if (bp > 0) {
Password1[i2] = longKey2[i2] - encryptedPass5[i2];
bp--;
}
else if (ap == 0 && bp == 0) {
ap = a;
bp = b;
i = i - 1;
}
这解决了问题。
与其他函数相同:
for (i = 0; i < n; i++) {
if (ap > 0) {
encryptedPass[i] = longKey1[i] + password4[i];
ap--;
}
else if (bp > 0) {
encryptedPass[i] = longKey1[i] - password4[i];
bp--;
}
else if (ap == 0 && bp == 0) {
ap = a;
bp = b;
i = i - 1;
}
当我加密时不再有 -858993460,也不再有╠╠╠
No more "-858993460" when I encrypt and no more "╠╠╠╠╠╠╠╠" when I printf the password in the reverse process.
再次感谢大家,对于原消息的长度,我们深表歉意。
下次我将考虑到这一点。
Thank you all again, and sorry for the lenght of the original message. Next time I shall take that into account.
cd
这篇关于printf在屏幕上显示“ -858993460”。或“╠╠╠╠╠╠╠╠”;这些是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!