Teaching algebra to a class of excited 13-year-olds, fresh from a drama class at the end of the school day, is a tall order.
But maths teacher Steve Lomax did just that by persuading them they were spies on a mission to crack codes using mathematics.
Mr Lomax, a teacher at Tewkesbury school, Gloucestershire, said: "My Year 8s would come from drama, very hyper. It was not a very productive lesson.
They hated algebra - the mere mention of it and they switched off.
"But when I wrote the questions in code and asked them to break the code, they were gripped."
Mr Lomax, also a Gloucestershire maths consultant, was part of a team of academics, teachers, local education authority advisers and mathematicians behind a resource pack on Braille, Morse and the German Second World War Enigma code cracked by intelligence forces at Bletchley Park, to spice up maths lessons.
Martin Monk, of the education charity Gatsby Technical Education Projects, which funded the pack, said: "Children think maths is boring. Looking at codes such as Enigma helps youngsters to see that maths can have a life-and-death application."
The pack was launched last Wednesday at Bletchley Park, the Buckinghamshire site of Allied code-breaking, which came up with the idea for the pack.
Alison Taylor, a maths teacher at Chipping Campden school, Gloucestershire, runs an annual code-cracking day, during which Year 7 pupils break a string of codes to find a hidden prize in the school.
"All you hear is that maths teachers are not making their lessons interesting enough," she said. "How do you think that makes us feel? There is a lot of pressure by the Government for us to hit targets, get good GCSE results and present the subject in an interesting way. But I think the two can be balanced."
Sally Cullen teaches her daughter Georgie, 10, from home, and last week they went on a trip to Bletchley Park organised by Bedford home educators.
"Georgie was not very good at maths at school," she said. "I think she was getting agitated about it. When I suggested times tables to her I was met with a blank wall.
"She is learning maths on her own now. She looks at her pocket money and works out what she can buy with it. After this visit, I will ask if she is interested in finding out more about codes, and we will see what happens."