title: Obfuscating a number(in a string) Objective C
body: <p>I'm using the following code to obfuscate a passcode for a test app of mine.</p>
  
  <pre><code>    - (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 &lt; [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];
  }
  </code></pre>
  
  <p>This works like a charm with all strings, but i've ran into a bit of a problem comparing the following results</p>
  
  <pre><code>NSLog([[self obfuscate:@"0000", @"maki"]); //Returns 0]&lt;W
  
  NSLog([[self obfuscate:@"0809", @"maki"]); //Returns 0]&lt;W
  </code></pre>
  
  <p>As you can see, the two strings with numbers in, while different, return the same result! Whats gone wrong in the code i've attached to result in the same result for these two numbers?</p>
  
  <p>Another example:</p>
  
  <pre><code>NSLog([self obfuscate:@"8000" withKey:@"maki"]); //Returns 8U4_
  NSLog([self obfuscate:@"8290" withKey:@"maki"]); //Returns 8U4_ as well
  </code></pre>
  
  <p>I may be misunderstanding the concept of obfuscation, but I was under the impression that each unique string returns a unique obfuscated string!</p>
  
  <p>Please help me fix this bug/glitch
  Source of Code: <a href="http://iosdevelopertips.com/cocoa/obfuscation-encryption-of-string-nsstring.html" rel="nofollow">http://iosdevelopertips.com/cocoa/obfuscation-encryption-of-string-nsstring.html</a></p>