Home > Back-end >  Can you tell me about the meaning of this code. Especially the inside of the loop
Can you tell me about the meaning of this code. Especially the inside of the loop

Time:09-24

# include & lt; Iostream>
using namespace std;
Int main () {
String k, c;
Cin> K> C;
for (int i=0; i{
Int t=(k [I % Kuala Lumpur ength ()] & amp; 31) - 1;
[I]=c (c [I] & amp; 31) - t> 0? C - t: [I] [I] - t + c;
}
Coutreturn 0;
}

CodePudding user response:

26 letters cycle,

CodePudding user response:

If there is a mathematical basis is understandable
 cin> K> C;//enter key, ciphertext 
for (int i=0; i{
Int t=(k [I % Kuala Lumpur ength ()] & amp; 31) - 1;//ciphertext corresponds to the current position of the key characters, namely ciphertext [I] the c I position corresponding to the key position, I
//because cipher (clear) may be longer than the key, and known key can be recycled, so after I location beyond the length of the k and starting from zero position,
//so I % Kuala Lumpur ength ()
//as for & amp; 31 processing, actually and % 32 processing are equivalent (why their equivalence in binary, don't dwell on here),
//and lowercase letters are just 32, namely the 'a' and 'a' ASCII just 32 difference, so the result of the % 32 lowercase letters are the same as
//and [I] % 32 k just to get the position of the corresponding characters,
//such as' a '% 32=1 (' a' % 32=1), which is equivalent to get letters a corresponding position (position starting from 0, so 1)
[I]=c (c [I] & amp; 31) - t> 0? C - t: [I] [I] - t + c; [I]//c % 32 is the same as the above said c [I] the characters corresponding to the location of the position - [I] t is calculated and k of relative distance
//if relative distance is greater than 0 c [I] - t for plaintext characters (plaintext: line + keys: column=cipher, which in turn is clear=ciphertext - key)
//is like case ciphertext 'H' % 32 - (key 'a' % 32-1)=clear 'H')
//if the distance is less than zero, the result plus 26 rounds a circle back (the equivalent of letters)
}
Cout
  • Related