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).
For that, I have:
a password (
char[]type);an encryption key (vector -
int[]type) that has the same length as thecharof the password;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:
- the first one (the value in
step[0]) is used to add the value (ASCII) starting from the first position of the passwordcharto the first position of the encryption key vector for a number of steps equal to the first stepstep[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].
- 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]).
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.
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).
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]);
}
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
why does it show "-858993460"?
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]);
}
then this message appears:
côő~ypaXOF╠╠╠╠╠╠╠╠
what is "╠"?
this "╠╠╠╠╠╠╠╠" is an incorrect display (the rest "côő~ypaXOF" is correct).
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.
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).