1

I need to encrypt and decrypt NSStrings. It doesn't have to be secure (at all!) just unreadable to an average user. Something as simple as a shift cipher would work alright, but I would like an algorithm slightly less obvious to the user.

Is there something built in to the iOS sdk that does this already? Maybe RSA encryption? Or a simple to code algorithm that wouldn't look like a one to one character exchange? Thank you!

Dash
  • 16,728
  • 6
  • 46
  • 48

4 Answers4

1

How about Base64.

It's completely non-secure, and although unreadable it will be a fairly obvious encoding scheme for anyone remotely knowledgeable in IT.

Implementation details : How do I do base64 encoding on iphone-sdk?

Community
  • 1
  • 1
PaulG
  • 13,531
  • 9
  • 55
  • 74
1

What about ROT13? It was already used in ancient Rome, fun to use, not save.

Or use string encoding as used for URLs in web technologies.

alex
  • 2,444
  • 23
  • 31
1

You could use a substitution cypher. Just prepare a 255 byte array with indexes from 1 to 255, scramble the array and replace each byte with the corresponding index value. Another easy cypher employs a key of length N, consisting of positive and negative offsets. Each byte of the nsstring gets shifted - the first by the value of the first offset, the second by the second and the k-th by the value of the (k mod N)-the. It is much harder to spot for the average, unmotivated user, and almost as easy to implement as a single shift cypher.

LSerni
  • 53,899
  • 9
  • 63
  • 106
1

As well as the other suggestions, you could also try Vigenère, which seems to meet your design criteria: simple and unreadable.

rossum
  • 14,876
  • 1
  • 21
  • 36