Wiktionary says that cypher comes from Old French cyfre, which itself comes from Arabic. But ph is usually a transliteration of Greek phi. So how does it get into a French word?
A blog entry by linguist Anatoly Liberman offers some insight into these and other "anomalous" spellings involving ph:
In short, one must chalk it up to the absurdities of prescriptive spelling and pronunciation.
It’s because medieval Latin sometimes used ciphra. The OED says of the word cipher, also spelt cypher, that
The earliest citations have it with a ph, and it has virtually never been spelt with an f in English. With numbers representing centuries (e.g., 4 means 14th century), the recorded forms in English are:
The OED provides no citation for the zifer spelling from the 17th century. Here are its earliest citations:
Personally, I am always flipflopping on the i spelling versus the y spelling, since I am always write cypher and then arguing with the spell-checkers. It appears that cypher is now in the minority, and has been for quite a while:
Apparently cypher is a bit common in the British corpus:
than it is in the American corpus:
So it appears that the cypher to cipher ratio is about 1:3 in the UK but closer to 1:16 in the US.