France's external intelligence service, the DGSE, has sponsored a school competition to find the nation's most talented young code-breakers.
It is the first time the DGSE has got involved in such a project in schools.
The first round drew in 18,000 pupils, and just 38 competed in the final on Wednesday, won by a Parisian team.
A DGSE spokesman said the aim was to spread awareness about intelligence work. Security is a major concern after last year's jihadist attacks in Paris.
DGSE stands for Directorate-General for External Security. It has 6,200 staff - 63% of them civilians - and an annual budget of about €750m (£575m; $839m).
Part of the intelligence service's work involves spying on Islamist groups. In November jihadist bombings and shootings in Paris, claimed by the Islamic State (IS) group, killed 130 people.
In January 2015 jihadists in Paris killed 17 people in attacks on the satirical magazine Charlie Hebdo, a policewoman and a Jewish supermarket.
Two associations of mathematicians - France-IOI and Animath - organised the cryptography tests for school pupils.
The competition was called Alkindi, after a celebrated 9th-Century Muslim Arab mathematician and philosopher, Abu Yusuf Yaqub Ibn Ishaq al-Kindi.
There were four rounds of tests on the internet, of increasing difficulty. The final was held at the Army Museum in Paris and the prizes included smart phones and computers.
The DGSE's role was to provide some help and funding for it, its spokesman told the BBC.
"It was a way for us to spread awareness about the DGSE's technical skills," he said.
"The aim wasn't to recruit youngsters but rather to inform, especially those pupils interested in maths, so that they can see the sort of work that the DGSE does."
'Culture of intelligence'
It was also "a way for us to spread a culture of intelligence in France", he said, arguing that it was "a contribution to developing citizenship". The official declined to be named.
But, in a separate statement, the intelligence service said it was also "seeking to remind people that the DGSE is trying to recruit young people skilled in information technology and maths and that it offers many professional opportunities in those areas".
It is the French equivalent of the UK's MI6 and the American CIA.
Nearly all the French regional education authorities got involved in the competition.
The organisers said boys and girls competed in almost equal numbers. Schools in the Paris region, Lille, Nantes and French overseas lycees (high schools) were the biggest participants.