title: Checksum and XOR in Swift
body: <p>I worte these methods in Objective-C. They're just checksum and XOR some <code>NSData</code></p>
  
  <pre><code>- (void)XOR:(NSMutableData *)inputData withKey:(NSData *)key
  {
      unsigned char* inputByteData = (unsigned char*)[inputData mutableBytes];
      unsigned char* keyByteData   = (unsigned char*)[key bytes];
      for (int i = 0; i &lt; [inputData length]; i++)
      {
          inputByteData[i] = inputByteData[i] ^ keyByteData[i % [key length]];
      }
  }
  
  - (Byte)checkSum:(NSMutableData *)data withLength:(Byte)dataLength
  {
      Byte * dataByte = (Byte *)malloc(dataLength);
      memcpy(dataByte, [data bytes], dataLength);
  
      Byte result = 0;
      int count = 0;
      while (dataLength&gt;0) {
          result += dataByte[count];
          dataLength--;
          count++;
      };
      result = result&amp;0xff;
      return result&amp;0xff;
  }
  </code></pre>
  
  <p>However, I'm not familiar with Bitwise operators, especially in Swift, with these <code>UnsafeMutablePointer&lt;Void&gt;</code>... things.</p>
  
  <p>Can anybody help me converting this ? (Basically, I need checksum and XOR functions) <br>
  One more things, should they be put in <code>NSData/NSMutableData</code> extension ?</p>
  
  <p>Thank you.</p>