31
loading...
This website collects cookies to deliver better user experience
XOR
operation on it and the corresponding bit from the secret key.true
if both of its inputs are opposites (one false and one true), otherwise, it returns false
.true XOR false = true
false XOR true = true
true XOR true = false
false XOR false = false
<small id="shcb-language-1"><span>Code language:</span> <span>PHP</span> <span>(</span><span>php</span><span>)</span></small>
hello world = 01101000 01100101 01101100 01101100 01101111 00100000 01110111 01101111 01110010 01100100
I not know = 01001001 00100000 01101110 01101111 01110100 00100000 01101011 01101110 01101111 01110111
XOR
operation on all the data.01101000 01100101 01101100 01101100 01101111 00100000 01110111 01101111 01110010 01100100
XOR
01001001 00100000 01101110 01101111 01110100 00100000 01101011 01101110 01101111 01110111
=
00100001 01000101 00000010 00000011 00011011 00000000 00011100 00000001 00011101 00010011
<small id="shcb-language-2"><span>Code language:</span> <span>PHP</span> <span>(</span><span>php</span><span>)</span></small>
XOR
the ciphertext with the key and we’ll get the original message back.00100001 01000101 00000010 00000011 00011011 00000000 00011100 00000001 00011101 00010011
XOR
01001001 00100000 01101110 01101111 01110100 00100000 01101011 01101110 01101111 01110111
=
01101000 01100101 01101100 01101100 01101111 00100000 01110111 01101111 01110010 01100100
<small id="shcb-language-3"><span>Code language:</span> <span>PHP</span> <span>(</span><span>php</span><span>)</span></small>
01101000 01100101 01101100 01101100 01101111 00100000 01110111 01101111 01110010 01100100
=
hello world
func encrypt(plaintext, key []byte) []byte {
final := []byte{}
for i := range plaintext {
final = append(final, plaintext[i]^key[i])
}
return final
}
func decrypt(ciphertext, key []byte) []byte {
final := []byte{}
for i := range ciphertext {
final = append(final, ciphertext[i]^key[i])
}
return final
}
<small id="shcb-language-4"><span>Code language:</span> <span>Go</span> <span>(</span><span>go</span><span>)</span></small>
31