Halfway along the dangerous road to Kohat - deep in the lawless tribal belt between Pakistan and Afghanistan, and where Osama Bin Laden is widely believed to be sheltering - we passed a small whitewashed shrine that had recently been erected by the side of the road: "That is where the army ambushed and killed two al-Qaeda men escaping from Afghanistan," said Javed Paracha. "Local people soon began to see the two martyrs in their dreams. Now we believe that they are saints. Already many cures and miracles have been reported. If any of our women want to ask anything special from God, they first come here."
He added: "They say that each shahid [martyr] emitted a perfume like that of roses. For many days a beautiful scent was coming from the place of their martyrdom."
Javed Paracha is a huge, burly tribal leader with a granite outcrop of nose jutting from a great fan of grey beard. In many ways he is the embodiment of everything that US policy-makers most fear and dislike about this part of the Muslim world. For Paracha is a dedicated Islamist, as well as a wily lawyer who has successfully defended al-Qaeda suspects in the Peshawar High Court. In his fortress-like stronghouse in Kohat he sheltered wounded Taliban fighters - and their frost-bitten women and children - fleeing across the mountains from the American Daisy Cutters at Tora Bora, and he was twice imprisoned by General Musharraf in the notorious prison at Dera Ismail Khan. There he was kept in solitary confinement while being questioned - and he alleges tortured - by CIA interrogators. On his release, he found his prestige among his neighbours had been immensely enhanced by his ordeal. His proudest boast, however, is building the two enormous madrasas he founded and financed, the first of which he says produced many of the younger leaders of the Taliban.
"They are the biggest madrasas in the [North-West] Frontier," he told me proudly after stopping to say a prayer at the al-Qaeda shrine. "The books are free. The food is free. The education is free. We give them free accommodation. In a poor and backward area like this, our madrasas are the only form of education. The government system is simply not here. "
Paracha got back in the car - the vehicle sinking to the left as he lowered himself into the back beside his two armed bodyguards - and added: "There are 200,000 jobless degree holders in this country. Mark my words, a more extreme form of the Taliban is coming to Pakistan. The conditions are so bad. The people are so desperate. They are waiting for a solution that will rid them of this feudal-army elite. The people want radical change. We teach them in the madrasas that only Islam can provide the justice they seek."
For better or worse, the sort of madrasa-driven change in political attitudes that Javed Paracha is bringing about in Kohat is being reproduced across Pakistan. An Interior Ministry report revealed recently that there are now 27 times as many madrasas in the country as there were in 1947: from 245 at the time of independence the number has shot up to 6,870 in 2001. The religious tenor of Pakistan has been correspondingly radicalised: the tolerant Sufi-minded Barelvi form of Islam is now deeply out of fashion, overtaken by the sudden rise of the more hardline reformist Deobandi, Wahhabi and Salafi strains of the faith that are increasingly dominant over swaths of the country.
The sharp acceleration in the number of these madrasas first began under General Zia, and was financed mainly by Saudi donors (though ironically the US also played a role in this as part of the anti-Soviet Afghan jihad). Since the oil boom of the early 1970s a policy of exporting not just petroleum, but also hardline Wahhabism, became a fundamental tenet of Saudi foreign policy, partly a result of a competition for influence with Shia Iran. Although some of the madrasas were little more than single rooms attached to village mosques, others are now very substantial institutions: the Darul Uloom in Baluchistan is now annually enrolling some 1,500 boarders and a further 1,000 day-boys.
Altogether, there are now an estimated 800,000 to one million students enrolled in Pakistan's madrasas: an entire, free Islamic education system existing parallel to the increasingly moribund state sector, in which a mere 1.8 per cent of Pakistan's GDP is spent on government schools. The statistics are dire: 15 per cent of these schools are without a proper building; 52 per cent without a boundary wall; 40 per cent without water; 71 per cent without electricity. There is frequent absenteeism of teachers; indeed, many of these schools exist only on paper.
This education gap is the most striking way in which Pakistan is lagging behind India, a country in which 65 per cent of the population is literate, and the number rises every year. Only this year, the Indian education system received a substantial boost of state funds in the government Budget; but in Pakistan the literacy figure is well under half (it is currently 42 per cent), and falling. The collapse of government schooling has meant that many of the country's poorest people who want their children's advancement have no option but to place the children in the madrasa system where they are guaranteed a conservative and outdated, but nonetheless free education.
Madrasas are now more dominant in Pakistan's educational system than they are anywhere else; but the general trend is common across the Islamic world. In Egypt the number of teaching institutes dependent on the Islamic Al-Azhar University increased from 1,855 in 1986 to 4,314 ten years later. The Saudis have also stepped up funding in Africa: in Tanzania alone they have been spending $1m a year building new madrasas. In Mali, madrasas now account for around a quarter of children in primary schools. Seen in this wider context, Paracha and his educational endeavours in Kohat raise a number of important questions: how far are these madrasas the source of the problems that culminated in the Islamist attacks of 9/11? Are madrasas simply terrorist factories? Should the west be pressing US client states such as Pakistan and Egypt simply to close the whole lot down?
In the panic-striken aftermath of the Islamist attacks on America, the answers to these questions seemed obvious. Donald Rumsfeld, among a number of US politicians, fingered madrasas as terror-incubators and centres of hatred, responsible - so he said - for propagating anti-Americanism across the Islamic world. There were many good reasons for people jumping to this assumption. The terrifyingly ultra-conservative Taliban regime was unquestionably the product of Pakistan's madrasas. Much of the Taliban leadership was trained at just one madrasa: the Haqqaniya at Akora Khattak, between Islamabad and Peshawar. The director, Sami ul-Haq, still proudly boasts that whenever the Taliban put out a call for fighters, he would simply close down the madrasa and send his students off to fight.
But as we now know, in the aftermath of 9/11, a great many of the assumptions that people made about Islamist terrorism have proved with hindsight to be quite spectacularly ill-founded, the result of inadequate and partial understanding of the complexities of the contemporary Islamic world.
There was, first of all, widespread misunderstanding about the nature of al-Qaeda. Bin Laden's organisation has turned out not to be some structured multinational organisation; still less was it the state-sponsored puppet - with Osama moving to the tug of Saddam's Ba'athist string-pulling - that was depicted by the neo-cons and their media mouthpieces (in this country, Conrad Black's Daily Telegraph and the equally credulous Murdoch Times) as they attempted to justify attacking Iraq.
Instead, as Giles Kepel, the leading French authority on Islamists, puts it in his important study, The War For Muslim Minds: "al-Qaeda was [and is] less a military base of operations than a database that connected jihadists around the world via the internet . . . this organisation did not consist of buildings and tanks and borders but of websites, clandestine financial transfers and a proliferation of activists ranging from Jersey City to the paddies of Indonesia". This central failure to understand the nature of al-Qaeda was the reason that the US attempted to counter it with such unsuitable policies: by targeting nations it considered sponsors of terrorism, so inadvertently turning itself into al-Qaeda's most effective recruiting agency.
In the same way, it was maintained that al-Qaeda's grievances were unconnected to America's Middle Eastern policies. This also proved to be quite wrong. From al-Qaeda's "Declaration of War Against the Americans", issued in 1996, Bin Laden had announced that his grievance was not cultural or religious, but very specifically political: he was fighting to oppose US support for the House of Saud and Israel. As he told the Pakistani journalist Hamid Mir: "America and its allies are massacring us in Palestine, Chechnya, Kashmir and Iraq. The Muslims have a right to attack America in reprisal . . . The targets were icons of America's military and economic power."
In retrospect, the idea that madrasas are one of the principal engines of this global Islamic terrorism appears to be another American assumption that begins to wobble when subjected to serious analysis.
It is certainly true that many madrasas are fundamentalist in their approach to the scriptures and that many subscribe to the least pluralistic and most hardline strains of Islamic thought. It is also true that some madrasas can be directly linked to Islamic radicalism and occasionally to outright civil violence: just as there are some yeshivas [religious schools] in settlements on the West Bank that have a reputation for violence against Palestinians, and Serbian monasteries that sheltered some of the worst of that country's war criminals, so it is estimated that as many as 15 per cent of Pakistan's madrasas preach violent jihad, while a few have even been known to provide covert military training.
Some have done their best to bring about a Talibanisation of Pakistan: madrasa graduates in Karachi have been behind acts of violence against the city's Shia minority, while in 1998, madrasa students in Baluchistan began organising bonfires of TVs and attacked video shops. In this, however, they have so far had limited success. Indeed, the bestselling video in Baluchistan last year was a pirate tape that showed a senior Pakistani MP in flagrante with his girlfriend. The tape, which had been made by the MP himself, had been stolen by his political enemies and circulated around the province, with the expectation that it would destroy his career. However, so impressive was the MP's performance in the video that he was re-elected with a record majority; I recently met him looking very pleased with himself in Islamabad, where he says the tape has transformed his political fortunes.
It is now becoming clear, however, that producing cannon-fodder for the Taliban and graduating local sectarian thugs is not at all the same as producing the kind of technically literate al-Qaeda terrorist who carried out the horrifyingly sophisticated attacks on the USS Cole, the US embassies in East Africa, and the World Trade Center. A number of recent studies have emphasised that there is an important and fundamental distinction to be made between most mad- rasa graduates - who tend to be pious villagers from economically impoverished backgrounds, possessing very little technical sophistication - and the sort of middle-class politically literate global salafi jihadis who plan al-Qaeda operations around the world. Most of these turn out to have secular, scientific or technical backgrounds and very few actually turn out to be madrasa graduates.
The men who planned and carried out the Islamist attacks on America - all but four of them were Saudi citizens - have often been depicted in the press as being "medieval fanatics". In fact, it would be more accurate to describe them as confused but highly educated middle-class professionals: Mohammed Atta was an architect and a town-planning expert; Ayman al-Zawahiri, Bin Laden's chief of staff, was a paediatric surgeon; Ziad Jarrah, one of the founders of the Hamburg cell, was a dental student who later turned to aircraft engineering; while Omar Sheikh, the kidnapper of the Wall Street Journal reporter Daniel Pearl, had studied at the LSE and was the product of the same British public school that produced the film-maker Peter Greenaway.
Such figures represent a clash of civilisations occurring not so much between civilisations, as the author Samuel Huntingdon would maintain, but rather within individuals, products of the sort of cultural dislocation and disorientation that accompanies accelerating economic change and globalisation. As Kepel puts it, the new breed of global jihadis are not the urban poor of the developing world, so much as "the privileged children of an unlikely marriage between Wahhabism and Silicon Valley".
This is also the conclusion drawn by the most sophisticated analysis of global jihadis to be published in recent years: Marc Sageman's Understanding Terror Networks. Sageman is a forensic psychiatrist and former CIA man who worked in Pakistan during the 1980s. In his study, he closely examined the lives of 172 al-Qaeda-linked terrorists, and his conclusions have demolished much of the conventional wisdom about who joins jihadi groups: two-thirds of his sample were middle class and university-educated; they are generally technically minded professionals and several have PhDs. Nor are they young hotheads: their average age is 26, most of them are married, and many have children. Only two appear to be obviously psychotic. It seems that Islamic terrorism, like its Christian predecessor, remains a largely bourgeois endeavour: "These are truly global citizens," writes Sageman, "familiar with many countries - the west as well as the Middle East - and able to speak several languages with equal facility . . . Even their ideologues are not trained clerics: [Sayyid] Qutb [for example] was a journalist."
It is true that there are exceptions, and the line between these two different worlds is certainly porous. There are several examples of radical madrasa graduates who have become involved with al-Qaeda. By and large, however, madrasa students simply do not have the technical expertise or conceptual imagination necessary to carry out the sort of attacks we have seen al-Qaeda pull off in the past few years. Instead, the concerns of most madrasa graduates remain far more traditional - what the French Islamist expert Olivier Roy calls "neo-fundamentalism": the correct fulfilment of rituals, how to wash correctly before prayers, the proper length to grow a beard and how high above the ankles you should wear your salwar kameez. As the laws of the Taliban regime revealed, they are obsessed with the public covering of women, which they regard as essential to a morally ordered society. Their focus, in other words, is not on opposing non-Muslims or the west - the central concern of the salafi jihadis - so much as on fostering what they see as proper Islamic behaviour at home and attempting to return to - as they see it - the pristine purity of the time of the Prophet.
That there are huge variations in the tone and quality of madrasa education should not be surprising. Throughout much of Islamic history, madrasas were the major source of religious and scientific learning, just as the church schools and the universities were in Europe. The quality and tone of their education is determined by the nature of their curricula, which have always varied widely.
Between the seventh and 11th centuries, madrasas produced free-thinking luminaries such as Alberuni, Ibn Sina and al-Khwarizmi. The oldest and greatest madrasa of them all, Al-Azhar University in Cairo, has good claim to being the most sophisticated institution of learning in the entire Mediterranean world during the early Middle Ages. The very idea of a university in the modern sense - a place of learning where students congregate to study a variety of subjects under a number of teachers - is generally regarded as an innovation first developed at Al-Azhar.
When the Mongol invasions destroyed the major institutions of learning in the central Islamic heartlands, many learned refugees fled to Delhi, turning northern India for the first time into a major centre of scholarship. By the time of Akbar, the third Mughal emperor of India, the curriculum in Indian madrasas blended the learning of the Islamic Middle East with that of the indigenous teaching of Hindu India, which resulted in the incredibly broad-minded and pluralistic high civilisation of the Mughal period.
However, following the collapse of Indo-Islamic self-confidence that accompanied the deposition and exile of the last emperor, Bahadur Shah Zafar, in 1858, disillusioned scholars founded an influential but depressingly narrow-minded Wahhabi-like madrasa at Deoband, 100 miles north of the former Mughal capital. Reacting against what the founders saw as the degenerate ways of the old elite, which had allowed the British to defeat Muslim power in such a catastrophic manner, the Deoband madrasa went back to Koranic basics, rigorously stripping out anything Hindu or European from the curriculum of the college. It was, unfortunately, these puritanical Deoband-type madrasas that spread throughout northern India and Pakistan in the course of the 20th century, and which particularly benefited from the patronage of Zia and his Saudi allies in the 1980s.
It is certainly true that many madrasas in Pakistan have outdated curricula: some still teach Euclidian geometry and medicine from the Roman physician Galen of Pergamum. Emphasis is put on the rote learning - rather than critical study - of the Koran. Jessica Stern of Harvard recently testified before a US Senate House committee that "in a school that purportedly offered a broad curriculum, a teacher I questioned could not multiply seven times eight". This is, however, by no means the case with all madrasas, some of which are surprisingly sophisticated places.
In Karachi, the largest madrasa is the Darul Uloom. To get there, you pass from the rich middle-class areas of the city centre, with their low, white bungalows and sprawling gardens, going through progressively more run-down suburbs until you find yourself in a depressing industrial wasteland of factories and warehouses, punctuated by the belching smokestacks of brickworks. Out of this Pakistani apocalypse rises the almost surreal spectacle of Darul Uloom. Its green lawns resemble a cross between a five-star hotel and a rather upmarket, modern university campus.
After what happened to Daniel Pearl, I had been warned about the dangers of visiting madrasas, and had gone to the elaborate lengths of informing the British Consulate about my movements; but in reality there was nothing remotely threatening about Darul Uloom. The students were almost all eager, smart, friendly and intelligent, if somewhat intense and puritanical. When, on a visit to the dormitory block, I asked one bearded student what music he listened to on his shining new ghetto-blaster, he looked at me as if I had just asked him about his favourite porn video. The machine, he informed me, was only for listening to tapes of sermons. All music was banned.
Puritanical it may be, but it is clear that the Darul Uloom performs, as do many Pakistani madrasas, an important service - especially in a country where 58 per cent of the vast population, and 72 per cent of women, are illiterate and half the population never see the inside of a school at all. Madrasas may not be cutting-edge in their educational philosophy, but they do provide the poor with a way of gaining literacy and a real hope of advancing themselves. In certain traditional subjects - such as rhetoric, logic, jurisprudence and Arabic grammar - the teaching can be outstanding. Although they tend to be ultra-conservative, it has been repeatedly shown that only a small proportion are obviously militant. To close them down without attempting to build up the state sector would simply relegate large chunks of the population to illiteracy and ignorance. It would also be tantamount to instructing Muslims to stop educating themselves about their religion - hardly the best strategy for winning hearts and minds.
You don't have to go far from Pakistan to find a madrasa system that has effectively tackled both the problems of militancy and of educational backwardness. Although India was originally the home of the Deobandi madrasas, such colleges in India have no track record of producing violent Islamists, and are strictly apolitical and quietist. Their degree of success can be measured from the fact that Jamia Milia University in New Delhi, at least 50 per cent of whose intake comes from a madrasa background, is generally reckoned to be one of India's most prestigious and successful centres of higher education.
According to Seema Alavi, one of India's brightest young historians, who now teaches at Jamia, there is little difference between her students educated at secular schools and those educated in madrasas - except perhaps that those from madrasas are better able to memorise coursework, but are less practised at analysing and processing information: years of rote-learning has both its pros and its cons. But there is no sense that those students from Indian madrasas are more politically radical or less able to cope with a modern urban environment than their contemporaries from secular institutions. Several of India's greatest scholars - such as the celebrated Mughal historian Muzaffar Alam of Chicago University - are madrasa graduates.
If this is right, it would seem to confirm what other researchers have observed, that it is not madrasas per se that are the problem, so much as the militant atmosphere and indoctrination taking place in a handful of notorious centres of ultra-radicalism such as Binori Town or Akora Khattak.
The question remains, however, whether General Musharraf's government has the strength and the willpower to see through the necessary reforms and replicate the success of madrasas across the border in India. So far, attempts at taming Pakistan's more militant madrasas have proved half-hearted. There have been some attempts to curb the attendance of foreign Islamic students at Pakistani madrasas, and noises were made about standardising the syllabus and encouraging some modern subjects. Nevertheless, the more extreme have been able to resist the enforcement of even these mild measures: only 1 per cent of the country's madrasas complied when asked to register with the government.
In Islamabad, I went to see Pervez Hoodbhoy, an expert on education and the author of an important study of the madrasas. Hoodbhoy teaches at Quaid-e-Azam University, the Pakistani Oxbridge, and as we sat in the spacious campus, he described the depressing changes he had witnessed since joining the staff in the 1970s. Not only had there been a general decline in educational standards, he said, but beards, burkas and hijabs, unknown in the early 1980s, were now the norm. He estimated that only one-third of his students now resist showing some visible sign of their Islamic propriety. "And this," he added, "is by far the most liberal university in Pakistan.
"There is definitely a change in the temper of this society," he said. "The students are much less interested in the world and show much less curiosity - instead we have this mad, unthinking rush towards religiosity, and the steady erosion of the liberal elite."
I asked Hoodbhoy about his prognosis for the future.
"I am very anxious," he said. "The state educational system has reached the point of collapse. The only long-term solution has to be improved secular government schools: at the moment they are so bad that even where they exist, no one will willingly go to them.
"But the biggest problem we have," he continued, "is the US. Their actions in Iraq and Afghanistan have hugely strengthened the hands of the extremists and depleted the strength of those who want to see a modern, non-fundamentalist future for this country. Before the invasion of Iraq, I called the US ambassador and warned her: if you attack Saddam, you may gain Iraq, but you'll lose Pakistan. I hope I was wrong - but I fear that I may yet be proved right."
William Dalrymple's most recent book, White Mughals (Harper Perennial), won the Wolfson Prize for History. A stage version by Christopher Hampton has just been commissioned by the National Theatre