title: Finding a permutation of one string in another: Xor solution strange behavior
body: <p>I am working on the following problem: </p>
  
  <p><a href="https://i.stack.imgur.com/3gpAN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3gpAN.png" alt="enter image description here"></a></p>
  
  <p>I was inspired by <a href="https://stackoverflow.com/questions/2131997/checking-if-two-strings-are-permutations-of-each-other">the first answer to this question</a> to come up with a solution that utilizes some of the properties of XOR (Identity, Commutative, and Self-Inverse) to work in O(n) time and O(1) space.</p>
  
  <pre><code>def checkInclusion(s1: str, s2: str) -&gt; bool:
      # Checks for permutation of s1 inside of s2.
      # Xor's all of the characters in a s1-length window of s2
      # If xor_product = 0 --&gt; permutation identified
      # Relies on properties of xor to find answer: identity, communtative, and self-inverse
      xor_product = 0
      for i in range(0, len(s2) - len(s1) + 1):
          s1_index = 0
          for j in range(i, i + len(s1)):
              xor_product = xor_product ^ ord(s1[s1_index]) ^ ord(s2[j])
              s1_index += 1
          if xor_product == 0: return True
          xor_product = 0
      return False
  </code></pre>
  
  <p>This solution works for most inputs, but fails when <code>s1 = "kitten"</code> and <code>s2 = "sitting"</code>. Is this solution conceptually flawed? If so, then how? If not, then what's the bug?
  I'm admittedly new to coding interview style questions. All help appreciated.</p>