As Maarten notes in the comments, you're indeed expecting rather too much from an old classical cipher designed to be used by hand. Ciphers from that era were simply not designed to be able to mechanically and unambiguously encode all possible messages.
Basically, as you've noted, the Playfair cipher as you've described it cannot encrypt all messages; specifically, it cannot handle messages where two consecutive identical letters fall into the same group, nor messages of odd length. (There are Playfair variants that can handle both of those in various ways, but you don't seem to be using any of those variants.)
It is thus the encryptor's responsibility to somehow ensure that their message is of a suitable form to be encrypted with the cipher, while still (hopefully) conveying the appropriate meaning to the recipient when decrypted.
One common convention for doing that is to break up unencryptable plaintext segments (or pad messages with an unsuitable length) by inserting a dummy letter that is obviously misplaced, and which the recipient can therefore safely ignore while reading the message. X
and Q
are common choices for such dummy letters, being rare in normal English text, but really any letter can be used. So, for example, if you needed to break up a rare double X
, you could e.g. turn it into XQX
or XZX
or whatever; it just needs to be something that the recipient can spot as an obvious error, and which they can be expected to be able to reliably correct.
But note that you also have other options: for example, you could simply choose to rephrase your message using different words that don't contain the problematic double letter. Or, for the specific case of the Playfair cipher, you could simply choose to insert an extra dummy letter somewhere earlier in the message (or just adjust your word choice to change the length of the message) so that the double letter now gets split between two encrypted letter pairs.
In any case, note that the Playfair cipher (like most ciphers of its era) has a much more significant limitation: it cannot encode spaces or punctuation. Thus, it cannot distinguish "inverse" from "in verse" or "No retreat!" from "No, retreat!". So you will in any case have to take care when composing your messages to avoid potential misunderstandings due to run-on words and sentences.
(Some of that ambiguity can also be reduced by conventions like, say, inserting an X
between words and a Q
between sentences. But such conventions are also just imperfect patches on top of a fundamentally limited encoding scheme.)
Of course, the Playfair cipher has other limitations too, like the inability to express letters outside the English alphabet. Indeed, it cannot even represent all the letters in the English alphabet, typically conflating I
and J
into a single symbol. Again, this is just something that the receiver is expected to be able to disambiguate based on context.