MCPcopy Create free account
hub / github.com/ElementsProject/elements / Xor

Method Xor

src/streams.h:348–364  ·  view source on GitHub ↗

* XOR the contents of this stream with a certain key. * * @param[in] key The key used to XOR the data in this stream. */

Source from the content-addressed store, hash-verified

346 * @param[in] key The key used to XOR the data in this stream.
347 */
348 void Xor(const std::vector<unsigned char>& key)
349 {
350 if (key.size() == 0) {
351 return;
352 }
353
354 for (size_type i = 0, j = 0; i != size(); i++) {
355 vch[i] ^= std::byte{key[j++]};
356
357 // This potentially acts on very many bytes of data, so it's
358 // important that we calculate `j`, i.e. the `key` index in this
359 // way instead of doing a %, which would effectively be a division
360 // for each byte Xor'd -- much slower than need be.
361 if (j == key.size())
362 j = 0;
363 }
364 }
365};
366
367template <typename IStream>

Callers 4

WriteMethod · 0.80
GetValueMethod · 0.80
ReadMethod · 0.80
BOOST_AUTO_TEST_CASEFunction · 0.80

Calls 2

sizeFunction · 0.70
sizeMethod · 0.45

Tested by 1

BOOST_AUTO_TEST_CASEFunction · 0.64