It is a classic good cop, bad cop routine. Libya is simultaneously trying to play the role of tough guy and victim in its dealings with the outside world, as it unleashes venom and shellfire on its opponents but pleads for a cease-fire and dialogue.

First came the bad cop, as Moammar Gaddafi vowed to disinfect his country from the filth “house by house, room by room, alley by alley, person by person.” The rebels were described as “al-Qaeda drunks,” “armed gangsters,” “terrorists” or simply “tick-infested rats.”

Yet in the past two weeks, some officials in Tripoli seem to have realized that defiance, although playing well to Gaddafi’s supporters at home, does not play well in the outside world.

So a new line has emerged, embodied in a more conciliatory speech that Gaddafi delivered last weekend — the Libyan government as peacemaker, a regime that accepted an African Union peace plan rejected by the rebels, a misunderstood administration that has been picked on by former friends abroad but that still wants to solve its problems through dialogue.

“The sense of being unappreciated and misunderstood is a long-standing feeling among Libyans,” and especially in Gaddafi’s mind, said Lisa Anderson, president of the American University in Cairo. “That’s combined with a kind of defiance. . . . They are two sides of the same coin.”

The two approaches are often uncomfortably juxtaposed, as officials propose dialogue but in the same breath denounce the rebels as terrorists who represent no one, essentially a movement not worth talking to.

A common refrain is that Libya was dealing with an armed insurrection, a plot hatched with foreign help, and with protesters who turned violent, seizing arms and burning police stations. Perhaps a few civilians were killed, but “at most 150 to 200,” in Gaddafi’s words.

Any state would defend itself against an armed uprising, just as the United States was forced to react to an armed cult in Waco, Tex., in 1993. Israel can shell the Gaza Strip, and Bahrain and Syria can kill and imprison protesters, but no one is going to war with them, Libyan officials say.

“Even if we suppressed protests, dozens of countries suppressed protests,” government spokesman Moussa Ibrahim said. “The Security Council said the Libyan government committed massacres. Of course people died, but it’s not on that scale.”

Officials who worked hard to repair relations with the West during the past decade complain of feeling “betrayed” by their former friends in Washington and London, saying the West abandoned them almost overnight.

“I'm not defending what happened — there was bad management — but it doesn’t warrant war,” said one senior government official, speaking on the condition of anonymity to speak more freely.

“Okay, so there were demonstrations and some policemen got upset. So what is the role of ambassadors? What is the point of building up good relations? Ambassadors are there to mediate, cool things down.”

In the narrative of the Libyan government as peacemaker and victim, reform was already coming to Libya under the guidance of Gaddafi’s second son, Saif al-Islam.

Libya, once a pariah state, came in from the cold after it surrendered two men in 1999 accused of conspiring to bomb a Pan Am airliner over Lockerbie, Scotland, more than a decade earlier. In 2003, it agreed to forsake its weapons of mass destruction program, paving the way for diplomatic relations to be restored with the United States.

“One day you’re good, and the next you are bad, bad, bad,” the official said. “One day Obama is calling Gaddafi ‘Brother Leader,’ and the next day it’s ‘Gaddafi, pack and go.’ ”

Enter the good cop, dressed in the garb of innocent victim of foreign aggression.

“If people want to protect civilians, we have again and again declared we are ready for negotiations, ready for roadmaps for peace, ready for political transitional periods, ready for elections,” Ibrahim said at a news conference on announcing the death of Gaddafi’s son and Saif al-Islam’s younger brother, Saif al-Arab, and three of his grandchildren in a NATO airstrike.

“NATO does not care to test our promises. The West does not care to test our statements; it only cares to rob us of our freedom, our wealth which is oil, and our right to decide our future.”

These arguments fail to impress scholars or diplomats.

“The argument that the West abandoned them is grossly superficial. The plain fact of the matter is they have got no friends,” said Sir Richard Dalton, British ambassador in Tripoli from 1999 to 2002.

No countries voted against the Security Council resolution in March allowing military action against Libya, which cited systematic attacks against the civilian population that could amount to “crimes against humanity.”

The Arab League, the African Union and the secretary general of the Organization of the Islamic Conference joined in the condemnation.

“What the hell do the Libyans expect when they behave the way they did after Feb. 17?” Dalton said.

Diplomats acknowledge that some protests did turn violent on the night of Feb. 17, with police stations burned in parts of Tripoli and weapons taken. But witnesses say that live ammunition was aimed directly at unarmed people.

Human Rights Watch says at least 428 protesters were shot and killed in Libya between Feb. 17 and 21, including 76 in Tripoli.

Libya has been ruled as a totalitarian state based on the Gaddafi personality cult for more than four decades, and not surprisingly Saif al-Islam’s efforts to gently introduce more democracy and freedom ran aground long before February.

Blocked by hard-liners at every turn, his charity and development foundation announced late last year that it would no longer promote human rights and political reform in Libya. Many of the leading figures in the rebel Transitional National Council had once been part of Saif’s efforts to reform Libya but had given up hope well before February and resigned their posts.

When the people of Tunisia and Egypt took to the streets, Libya’s regime had little to offer but its iron grip, only tighter and bloodier.

The government’s offer of dialogue is belied by venomous rhetoric, continuous arrests of opposition activists and the shelling of residential areas in the besieged city of Misurata.

“Both sides have concluded there is nothing to be gained by surrender, because they’ll be killed by the people they surrender to,” Anderson said. “They will fight to the finish.”