When the Emir of Qatar flew to see President Abdelaziz Bouteflika of Algeria early this summer, he had one message to convey: don't help the Gaddafi regime. In other words, don't replace the dictator's Nato-destroyed armour with identical tanks and personnel carriers from the Algerian army. Word has it – meaning very good Arab military sources say – that Mr Bouteflika, almost as much a façade for the military authorities in Algeria as Mr Assad is for the Baath party in Damascus, gave all the necessary promises and then broke them. An awful lot of Gaddafi's Russian-made desert armour appears to be new; it didn't get its spotless shine after rotting in the desert for the past five years.

Qatar's role in the Libyan conflict remains one of the untold stories of the war – there were Qatari flags waved in Martyrs' Square in Tripoli last week – but so does Algeria's. Arabs were not surprised that so many of Gaddafi's family turned up in Algeria this week. For years, the Algerians have supported Gaddafi's independent – albeit crazed – policies because their own history has taught them to never accept orders from abroad. The moment the French – occupiers, colonisers and persecutors of Algeria for 132 years – bombed Libya, the Gaddafi regime's struggle to survive became a re-enactment of the Algerian FLN's 1954-62 battle for freedom against French rule. If the Libyans have been deprived of serious school history books for more than four decades, they know their country's travails all too well. For the Fezzan, the stony deserts and mountains south of the coastal cities, was occupied by French troops long after the Second World War to protect the frontier of Algeria – then still part of the French empire. The arid frontier between Libya and Algeria has been a smugglers' trail for centuries. Carrying the Gaddafi family into exile was not a major military operation.

Indeed, it was typical of the Algerian foreign ministry to announce the presence of the Gaddafi family on Algerian soil. Algerians like to show the West – especially the French – their freedom, the sacred trust of Algerian nationhood, damaged in the Islamist 1990-98 uprising, is not going to be traded for Western favours.

There would be no "Gaddafi-family-in-secret-Algerian-exile" headlines; Algeria had every right to show humanitarian sympathy for fellow Arabs; Nato's rebel allies can claim the Algerian offer of sanctuary as "an act of aggression" if they wish. Besides, Gaddafi's battle against his own Islamist enemies – minuscule compared to the Algerian government's ferocious war against its own al-Qa'ida style antagonists – made the Gaddafi dictatorship and successive Algerian military "democrat" regimes into allies. Why should proud Algeria now abandon its old brother Muammar just because the Arabs of the Gulf and the European powers (some of them, at least) have turned against him? French President Nicolas Sarkozy may embrace Gaddafi in 2007 and bomb him less than four years later. Algeria does not turn on its own friends.

That, at least, is how the pouvoir in Algiers can explain all this. But there are darker, bloodier contacts between the two countries' security services, which have used torture, political killing and massacre to assert their will over their people; the Algerians many times passed on the fruit of their "anti-terrorist" experience to Gaddafi's mukhabarat. The Algerian tale contained more bloodbaths – 150,000 deaths, mostly civilians, scarcely measures up to the fewer tortures and murders in Gaddafi's Libya – but both governments knew that to retain power meant wielding terrible power.

Besides, Algeria does not intend to be a second Libya. The country is freer and marginally more democratic than it was in the dreadful 1990s. But it believes – not without reason – that the Libyan revolution gathered Western support because Gaddafi's land is so rich in oil.

Algeria itself possesses the eighth-largest natural gas reserves in the world and is the fourth-largest gas exporter. Beneath its deserts lie 12.5 billion barrels of oil reserves and 27 per cent of current oil exports are bought by the United States. Algerians are well aware that if Libya's national export was potatoes, the West would no more have intervened than it would have invaded Iraq if Saddam Hussein's principal resource was asparagus.