The Prince of Wales tried his hand at the famous Enigma code-breaking machine when he visited the world's oldest existing intercept station.
Charles, who is patron of the intelligence services, was shown around GCHQ Scarborough to help celebrate its centenary year.
The base, which has more than 200 staff on site, was first established in Scarborough by the Royal Navy in 1914 as a wireless telegraphy station.
It then relocated to its current home at Irton Moor, North Yorkshire, in 1943.
The Prince saw the original bunker which was in operation until the 1970s as well as the station's museum which houses various listening and decoding devices.
He was also able to type a message into an original Enigma machine, which he said was "fascinating".
An outstation of the main GCHQ site in Cheltenham, the site near Scarborough played a key role in tracking the famous German battleship the Bismarck.
During the tour the Prince asked questions about the equipment he was being shown and how it was used during the war.
He was also able to meet members of staff at the base and was briefed on some current operational work that Scarborough does.
Making his first visit to the base, Charles was shown round the site by the Lord Lieutenant of North Yorkshire, Lord Crathorne, as well as a retired GCHQ historian.
A GCHQ spokesman said: "It is a real pleasure for us to host a visit by his Royal Highness to our Scarborough site in this centenary year so that he can meet staff and see firsthand the vital work they do in keeping the country safe.
"The Prince has long been a strong supporter of the work of the intelligence agencies and his presence here today is a reminder of that."