Karel and the Cardan Grille

The Cardan Grille, invented around 1550, belongs to the oldest encryption techniques.

“In 1550, Girolamo Cardano (1501-1576), known in French as Jérôme Cardan, proposed a simple grid for writing hidden messages. He intended to cloak his messages inside an ordinary letter so that the whole would not appear to be a cipher at all. Cardinal Richelieu (1585-1642) was reputed to be fond of the Cardan grille and to have used it in both private and diplomatic correspondence. “ [Wikipedia]

Here is how it can be used: Create a 6×6 (or smaller or larger) square table, with empty fields. Align the Cardan Grille on it. In the 6×6 case, the grille can have up to 9 holes. Let’s assume that it has 9. Write the first 9 letters of your message into the empty slots, letter by letter. Then rotate the grille by 90 degrees. If the grille is constructed correctly, this uncovers 9 new empty slots. Write the next 9 letters of your message into them. And so on. After rotating the grille 4 times, you wrote 36 letters, which is exactly the capacity of the 6×6 table.
However, it is easy to make a mistake while constructing a Cardan Grille. When the grille is faulty, there will be a position in the table that will be uncovered by more than one hole during the four rotations. Write a program for Karel the Robot to check if the grille is OK or not!