Domanda di colloquio di Microsoft

Q: How would you write this encryption function?