다음 코드를 사용하여 광산의 테스트 앱에 대한 암호를 난독 화합니다.숫자 (문자열 내) 난독 화 목적 C
- (NSString *)obfuscate:(NSString *)string withKey:(NSString *)key
{
// Create data object from the string
NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];
// Get pointer to data to obfuscate
char *dataPtr = (char *) [data bytes];
// Get pointer to key data
char *keyData = (char *) [[key dataUsingEncoding:NSUTF8StringEncoding] bytes];
// Points to each char in sequence in the key
char *keyPtr = keyData;
int keyIndex = 0;
// For each character in data, xor with current value in key
for (int x = 0; x < [data length]; x++)
{
// Replace current character in data with
// current character xor'd with current key value.
// Bump each pointer to the next character
*dataPtr = *dataPtr++^*keyPtr++;
// If at end of key data, reset count and
// set key pointer back to start of key value
if (++keyIndex == [key length])
keyIndex = 0, keyPtr = keyData;
}
return [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
}
이 모든 문자열 매력처럼 작동하지만 다음과 같은 결과
NSLog([[self obfuscate:@"0000", @"maki"]); //Returns 0]<W
NSLog([[self obfuscate:@"0809", @"maki"]); //Returns 0]<W
당신이 볼 수 있듯이 을 비교하는 약간의 문제로 실행했습니다의 숫자와 두 개의 문자열, 다른 반면, 같은 결과를 반환! 이 두 숫자에 대해 동일한 결과가 발생하도록 첨부 한 코드에서 무엇이 잘못 되었습니까?
또 다른 예 :
NSLog([self obfuscate:@"8000" withKey:@"maki"]); //Returns 8U4_
NSLog([self obfuscate:@"8290" withKey:@"maki"]); //Returns 8U4_ as well
내가 난처의 개념을 오해 할 수 있지만 각각의 고유 한 문자열이 독특한 난독 문자열을 반환하는 인상이었다!
나 코드의 버그/결함 소스를 수정 도와주세요 : http://iosdevelopertips.com/cocoa/obfuscation-encryption-of-string-nsstring.html
구현에 문제가 있습니다. 코드를 C로 다시 작성하고 '0000', 'maki'및 '0809', 'maki''와 같은 결과를 얻었습니다 (http : : //ideone.com/mQcfch)). – dasblinkenlight