में चेकसम और एक्सओआर उद्देश्य-सी में इन तरीकों को worte। वे सिर्फ चेकसम हैं और कुछ 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;
}
हालांकि, मैं बिटवाइज़ ऑपरेटर्स से परिचित नहीं हूँ, विशेष रूप से स्विफ्ट में, इन UnsafeMutablePointer<Void>
साथ ... बातें XOR।
क्या कोई मुझे इसे परिवर्तित करने में मदद कर सकता है? (असल में, मुझे चेकसम और एक्सओआर फ़ंक्शंस की आवश्यकता है)
एक और चीजें, उन्हें NSData/NSMutableData
एक्सटेंशन में रखा जाना चाहिए?
धन्यवाद।
'unsafeBitCast' का उपयोग करने की कोई आवश्यकता नहीं है। उदाहरण के लिए: 'चलो K = UnsafeBufferPointer (प्रारंभ करें: UnsafePointer (key.bytes), गिनती: key.length) '। –
@MartinR अच्छी जानकारी के लिए धन्यवाद। मेरा कोड बेहतर हो गया। – findall
धन्यवाद। मैं इसका परीक्षण करूंगा और बाद में स्वीकार किए गए उत्तर को चिह्नित करूँगा;) –