Question

I'm not needing any serious security, I just need to stop 11 year olds with plist editors from editing their number of coins in my game with ease.

I created a function that takes a string, for each unicode value of a character it raises this unicode value by 220 plus 14 times the character number that it is in the string.

Obviously this will fail (I think) if the string was like a million characters long because eventually you run out of unicode characters, but for all intents and purposes, this will only be used on strings of 20 characters and less.

Are there any unicode characters in this range that will not be stored to a plist or will be ignored by Apple's underlying code when I save the plist so that when I retrieve it and decrypt the character will be gone and I can't decrypt it?

+(NSString*)encryptString:(NSString*)theString {
    NSMutableString *encryptedFinal = [[NSMutableString alloc] init];
    for (int i = 0; i < theString.length; i++) {
        unichar uniCharacter = [theString characterAtIndex:i];
        uniCharacter += +220+(14*i);
        [encryptedFinal appendFormat:@"%C", uniCharacter];
    }
    return encryptedFinal;
}

+(NSString*)decryptString:(NSString*)theString {
    NSMutableString *decryptedFinal = [[NSMutableString alloc] init];
    for (int i = 0; i < theString.length; i++) {
        unichar uniCharacter = [theString characterAtIndex:i];
        uniCharacter += +220+(14*i);
        [decryptedFinal appendFormat:@"%C", uniCharacter];
    }
    return decryptedFinal;
}
Was it helpful?

Solution

It works for a range of a string of length 20 characters or less if you are encrypting one of the first 26+26+10+30 characters in the unicode index at any given point along the 20 character line. It probably works higher, I just didn't test it any higher.

This is the code I created to test it, all unicode characters were stored in an NSString and stayed valid for counting later.

    int i = 0;
    NSMutableString *encryptedFinal = [[NSMutableString alloc] init];
    NSString *theString = @"a";
    int j = 26+26+10+30;//letters + capital letters + numbers + 30 extra things like ?><.\]!@$
    int f = 0;
    int z = 0;
    while (f < j) {
        while (i < 220+220+(14*20)) {
            unichar uniCharacter = [theString characterAtIndex:0];
            uniCharacter += +f;
            uniCharacter += +220+(14*i);
            [encryptedFinal appendFormat:@"%C", uniCharacter];
            i++;
        }
        z += i;
        f++;
        i = 0;
    }
    NSLog(@"%@", encryptedFinal);
    NSLog(@"%i == %i?", z, encryptedFinal.length);

OTHER TIPS

There are two thing that you can do:

  1. Save the number of coins using NSData rather than using NSNumber. Then use NSData+AES to encrypt it. You can even encrypt your entire .plist file to ensure that no other fields are changed.

  2. Security through obscurity. Just save the number of coins as an important sounding field. e.g.:Security Token Number. You can also create a bogus number of coins field whose value is ignored. Or maybe save the same value in both the fields and flag the user for cheating if the two values don't match.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top