XOR on two bytes objects

    Args:
        a (bytes): object 1
        b (bytes): object 2

    Returns:
        bytes: The XOR result
541674
def xor_bytes(a, b):
    
    assert isinstance(a, bytes)
    assert isinstance(b, bytes)
    assert len(a) == len(b)
    res = bytearray()
    for i in range(len(a)):
        res.append(a[i] ^ b[i])
    return bytes(res)
1357926
def Xor(bytestr, key):
  """"""
  # TODO(hanuszczak): Remove this import when string migration is done.
  # pytype: disable=import-error
  from builtins import bytes  # pylint: disable=redefined-builtin, g-import-not-at-top
  # pytype: enable=import-error
  precondition.AssertType(bytestr, bytes)

  # TODO: This seemingly no-op operation actually changes things.
  # In Python 2 this function receives a `str` object which has different
  # iterator semantics. So we use a `bytes` wrapper from the `future` package to
  # get the Python 3 behaviour. In Python 3 this should be indeed a no-op. Once
  # the migration is completed and support for Python 2 is dropped, this line
  # can be removed.
  bytestr = bytes(bytestr)

  return bytes([byte ^ key for byte in bytestr])
1102161
def signed_le(a, b):
    
    a, b = match_bitwidth(as_wires(a), as_wires(b), signed=True)
    r = a - b
    return (r[-1] ^ (~a[-1]) ^ (~b[-1])) | (a == b)
858604
def _xor8(ins):
    
    op1, op2 = tuple(ins.quad[2:])
    if _int_ops(op1, op2) is not None:
        op1, op2 = _int_ops(op1, op2)

        output = _8bit_oper(op1)  # True or X = not X
        if op2 == 0:  # False xor X = X
            output.append('push af')
            return output

        output.append('sub 1')
        output.append('sbc a, a')
        output.append('push af')
        return output

    output = _8bit_oper(op1, op2)
    output.append('call __XOR8')
    output.append('push af')
    REQUIRES.add('xor8.asm')

    return output
462240
private void xor(byte[] data, byte[] kdfOut, int dOff, int dRemaining) {
		for (int i = 0; i != dRemaining; i++) {
			data[dOff + i] ^= kdfOut[i];
		}
	}
604168
def _hash_pair(first: bytes, second: bytes) -> bytes:
    
    if first is None:
        return second

    if second is None:
        return first

    if first > second:
        return keccak(second + first)
    else:
        return keccak(first + second)
235060
def _DoubleDecoder():
  

  local_unpack = struct.unpack

  def InnerDecode(buffer, pos):
    # We expect a 64-bit value in little-endian byte order.  Bit 1 is the sign
    # bit, bits 2-12 represent the exponent, and bits 13-64 are the significand.
    new_pos = pos + 8
    double_bytes = buffer[pos:new_pos]

    # If this value has all its exponent bits set and at least one significand
    # bit set, it's not a number.  In Python 2.4, struct.unpack will treat it
    # as inf or -inf.  To avoid that, we treat it specially.
    if ((double_bytes[7:8] in b'\x7F\xFF')
        and (double_bytes[6:7] >= b'\xF0')
        and (double_bytes[0:7] != b'\x00\x00\x00\x00\x00\x00\xF0')):
      return (_NAN, new_pos)

    # Note that we expect someone up-stack to catch struct.error and convert
    # it to _DecodeError -- this way we don't have to set up exception-
    # handling blocks every time we parse one value.
    result = local_unpack('<d', double_bytes)[0]
    return (result, new_pos)
  return _SimpleDecoder(wire_format.WIRETYPE_FIXED64, InnerDecode)
5148
def _trivial_mult(A, B):
    
    if len(B) == 1:
        A, B = B, A  # so that we can reuse the code below :)
    if len(A) == 1:
        a_vals = A.sign_extended(len(B))

        # keep the wirevector len consistent
        return pyrtl.concat_list([a_vals & B, pyrtl.Const(0)])
105672
def safe_str_cmp(a, b):
    
    if _builtin_safe_str_cmp is not None:
        return _builtin_safe_str_cmp(a, b)
    if len(a) != len(b):
        return False
    rv = 0
    if isinstance(a, bytes) and isinstance(b, bytes) and not PY2:
        for x, y in izip(a, b):
            rv |= x ^ y
    else:
        for x, y in izip(a, b):
            rv |= ord(x) ^ ord(y)
    return rv == 0
331572
def has_xor(self):
        

        def _has_xor(expr):
            return isinstance(expr, pyvex.IRExpr.Binop) and expr.op.startswith("Iop_Xor")

        found_xor = False

        for block in self._function.blocks:
            if block.size == 0:
                continue
            for stmt in block.vex.statements:
                if isinstance(stmt, pyvex.IRStmt.Put):
                    found_xor = found_xor or _has_xor(stmt.data)
                elif isinstance(stmt, pyvex.IRStmt.WrTmp):
                    found_xor = found_xor or _has_xor(stmt.data)
            if found_xor:
                break

        if found_xor:
            return { CodeTags.HAS_XOR }
        return None
1272044
def equivalent(self, other):
        """"""
        f = Xor(self, self.box(other))
        return f.satisfy_one() is None
727069
public static byte[] xorAlignRight(byte[] b1, byte[] b2) {
        if (b1.length > b2.length) {
            byte[] b2_ = new byte[b1.length];
            System.arraycopy(b2, 0, b2_, b1.length - b2.length, b2.length);
            b2 = b2_;
        } else if (b2.length > b1.length) {
            byte[] b1_ = new byte[b2.length];
            System.arraycopy(b1, 0, b1_, b2.length - b1.length, b1.length);
            b1 = b1_;
        }

        return xor(b1, b2);
    }
148119
def secure_compare(a, b)
      fixed_length_secure_compare(::Digest::SHA256.digest(a), ::Digest::SHA256.digest(b)) && a == b
    end
1317001
def xor_key(first, second, trafaret):
    
    trafaret = t.Trafaret._trafaret(trafaret)

    def check_(value):
        if (first in value) ^ (second in value):
            key = first if first in value else second
            yield first, t.catch_error(trafaret, value[key]), (key,)
        elif first in value and second in value:
            yield first, t.DataError(error='correct only if {} is not defined'.format(second)), (first,)
            yield second, t.DataError(error='correct only if {} is not defined'.format(first)), (second,)
        else:
            yield first, t.DataError(error='is required if {} is not defined'.format('second')), (first,)
            yield second, t.DataError(error='is required if {} is not defined'.format('first')), (second,)

    return check_
81388
def bitop_xor(self, dest, key, *keys):
        """"""
        return self.execute(b'BITOP', b'XOR', dest, key, *keys)
765862
def client_proof(user, password, salt, A, B, a, hash_algo):
    
    N, g, k = get_prime()
    K = client_session(user, password, salt, A, B, a)

    n1 = bytes2long(hash_digest(hashlib.sha1, N))
    n2 = bytes2long(hash_digest(hashlib.sha1, g))
    if DEBUG_PRINT:
        print('n1-1=', binascii.b2a_hex(long2bytes(n1)), end='\n')
        print('n2-1=', binascii.b2a_hex(long2bytes(n2)), end='\n')

    n1 = pow(n1, n2, N)
    n2 = bytes2long(hash_digest(hashlib.sha1, user))

    M = hash_digest(hash_algo, n1, n2, salt, A, B, K)
    if DEBUG_PRINT:
        print('n1-2=', binascii.b2a_hex(long2bytes(n1)), end='\n')
        print('n2-2=', binascii.b2a_hex(long2bytes(n2)), end='\n')
        print('client_proof:M=', binascii.b2a_hex(M), end='\n')

    return M, K
1058291
def num2bytes(x, bytes):
    
    if not isinstance(x, int):  # If it is another "thing", just return ZEROs
        return tuple([0] * bytes)

    x = x & ((2 << (bytes * 8)) - 1)  # mask the initial value
    result = ()

    for i in range(bytes):
        result += (x & 0xFF,)
        x >>= 8

    return result