Coding interview challenge
Recently I was asked to write a method that takes a string, and then encrypts or decrypts it using the [ROT13] cipher technique. The challenge was to allow encryption and decryption based on any number passed in with the string as arguments.
For simplicity’s sake, let’s just say that I’m only concerned with ROT-13, and not ROT-5, ROT-10, etc.
There may be some better ways to do it (I’m quite certain there are), but this is what I came up with:
If you really want to wow your interviewer…
Now if you really want to go the extra mile and show your interviewer an even more secure ciper with many fewer lines of code, show them the code for ROT-26:
Sorry, bad joke… I’ll see myself out.
[rot13]:http://en.wikipedia.org/wiki/ROT13