Home > Back-end >  One-time password this problem, please, help, want to know why there are two mistakes, how should so
One-time password this problem, please, help, want to know why there are two mistakes, how should so

Time:09-26

# include & lt; Stdio. H>
# include & lt; Stdlib. H>
#include
#include
//byte into 8 bits string
Int ByteToBit (char ch, char bit [8])
{
For (int CNT=0; CNT & lt; 8; Cnt++)
{
bit/CNT=(ch & gt;> CNT) & amp; 1;
//ch binary values stored in the bit array}
//such as we pray for a binary and decimal constant divided by 2
return 0; }
Char GenerateRandom () {return rand () % 2; }
//make a one-time key
Void GenerateKey (char * p, int len)
{
Srand (time (0)); For (int I=0; i {
P=GenerateRandom [I] ();
Printf (" % d ", p [I]);
}
printf("\n");
}//exclusive or operation, save the results in p
Void XOR (char * p, char * q, int len) {printf ("========================================================\ n ");
For (int I=0; i {
P=p ^ q [I] [I] [I];
Printf (" % d ", p [I]); }
printf("\n"); }
//byte into 8 bits string
Int ByteToBit (char ch, char bit [8])
{the for (int CNT=0; CNT & lt; 8; Cnt++)
{bit [7 - CNT]=(ch & gt;> CNT) & amp; 1;
//ch binary values stored in the bit array
} return 0;
}
Void OneTimeAlgorithm ()
{int index=1;
While (index!=0)
{char plain [100]={0 x0};
Printf (" please enter the need to encrypt plaintext: ");
Gets (plain);
//store clear
Int len=strlen (plain);
//get the actual clear length
Int bitlen=sizeof (char) * * len;
//binary string length
Char * p=(char *) malloc (bitlen);
Char * key=(char *) malloc (bitlen);
For (int I=0; i {
ByteToBit (plain [I], p + I * 8);
}
for(int i=0; i{
Printf (" % d ", p [I]);
}
printf("\n");
GenerateKey (key, bitlen);
XOR (p, key, bitlen);
}
}

CodePudding user response:

1. Bytestobit this function you define the two times
2. The nested for loop, you with I as a loop variable