Microsoft interview question

Q: How would you write this encryption function?