I worte these methods in Objective-C. It is just a checksum and XOR NSData
- (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 < [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>0) { result += dataByte[count]; dataLength--; count++; }; result = result&0xff; return result&0xff; }
However, I am not familiar with bitwise operators, especially in Swift, with these UnsafeMutablePointer<Void> ... things.
Can someone help me convert this? (Basically, I need XOR checksums and functions)
One more thing if they should be added to the NSData/NSMutableData ?
Thanks.
source share