The fix
Before I accept this code, answer two things. One: how would you verify it actually works, what specific inputs or test cases would prove it? Two: what happens if [the key input] is empty, null, very large, or malformed? Walk each case and fix any that break.
Learn it properly: Recipe 05, Build β
Deeper dive: read the full article β