When I read a book today, I see: "The characteristics of the exclusive or operation are: if a ^ B = C, then C ^ B = A and C ^ A = B. This rule can be used
."
I plan to give it a try. I first assume that there is a key and then the number is given. However, in order to encrypt the key, the number ^ key can be re-obtained once the key is decrypted or different. So how much is the key.
So I first wrote
int a,b;cin>>a>>b;cout<<a^b;
Then, the compilation was naturally unable to pass. Later, I asked people everywhere to ignore me. I was a bit-wise or perhaps bit-wise, but int was 4 bytes, so it didn't match. Therefore, replace it with Char [] for saving. (I made a mistake at the beginning and explained it later)
The following code is attached:
# Include <iostream> using namespace STD; # define N 7 char key [] = {'A', 'B', 'C', 'D', 'E ', 'F', 'G'}; int main () {char number [N], encode [N]; for (INT I = 0; I <n; ++ I) cin> Number [I]; for (INT I = 0; I <n; ++ I) encode [I] = number [I] ^ key [I]; // encrypted for (INT I = 0; I <n; ++ I) cout <encode [I]; cout <Endl; For (INT I = 0; I <n; ++ I) cout <char (encode [I] ^ key [I]); // decrypt cout <Endl; System ("pause "); return 0 ;}
Another small problem is forced conversion. I found that the numeric type will change to int type after the difference or occurrence, and I have to force the conversion.
Here is a problem corrected. In fact, the reason why I cout <a ^ B; the error was actually because the priority of ^ is lower than the <symbol, because this problem can be solved with parentheses. -_-!
Cout <(a ^ B); I learned this time ..
In fact, ^ supports long, Int, short, and unsigned Int.