Born the son of a antiquarian bookseller in London, he demonstrated his skill at cryptography from an early age by deciphering his father's secret price codes. As a teenager, he earned pocket money by setting the Times crossword.
Marks joined the Armed Services in January 1942, and went to Bedford to train as a cryptographer. His original and unorthodox mode of thought led to him being the only one of his class judged not good enough to be sent to Bletchley Park; instead, he was sent to the poor relation of the intelligence services, the recently formed Special Operations Executive (SOE). (Later, when his abilities became apparent to all, Bletchley Park would refer to him as "the one that got away".)
Marks played a major role in the construction and security of SOE cyphers (initially double transposition ciphers), especially by his re-invention of the "one-time pad", re-organisation of the emergency poem cyphers, and by the recruitment of a special team (based at Grendon Underwood, Buckinghamshire) to cryptanlyse "indecipherables" (garbled messages which had to be cracked, or else order the agent to retransmit at great risk of capture). Marks also invented a new form of "security check" (a duress code) which is still classified.
To improve the security of emergency poem cyphers, his solution was to use original poems instead of famous ones. Many of these he wrote himself, the best known being that given to the agent Violette Szabo, The Life That I Have, which was used in the film made about Szabo, Carve Her Name With Pride (1958).
Marks was often angry at the carelessness he found in SOE. Early on he uncovered the German penetration of the SOE operations in the Netherlands, the so-called Englandspiel, but his suspicions were disregarded and up to fifty agents went unnecessarily to capture, torture and death. Marks had briefed many of these agents himself, including his close friend 'Tommy' Yeo-Thomas.
He left SOE in 1946 and declined an offer of employment from SIS. He went on to write a number of marginally successful plays and films, including The Girl Who Couldn't Quite (1947), Cloudburst (1951), The Best Damn Lie (1957), Sebastian (1967) and Twisted Nerve (1968), and also the script for Michael Powell's intelligent and highly controversial Peeping Tom (1960).
Marks' book about his work in SOE - Between Silk and Cyanide: A Codemaker's Story 1941-1945 (HarperCollins, 1998) became an instant classic.
He married the portrait painter Elena Gaussen in 1966, a marriage that lasted until shortly before his death.