See the entire field of number theory for something that didn't have applications when it was conceived. Gauss, Euler and the other early number theorists were essentially just amusing themselves with stuff like the phi function. Then cryptography became a serious open problem, and boom.