Last week’s massacre of 132 schoolchildren in Peshawar by the Tehrik-i-Taliban Pakistan (TTP) was horrific. It sparked a wave of sympathy—world leaders expressed their solidarity with the country—and also criticism—for years, Pakistan has given safe haven to terrorist groups.

TTP’s ghastly attack in Peshawar was hardly surprising. In the spring of 2010, Faisal Shahzad, a TTP-trained American, attempted to bomb Times Square in New York. Just weeks later, TTP operatives massacred 86 Ahmadi worshippers during Friday prayers at mosques in Lahore. (Ahmadis are a persecuted minority Muslim sect.) In 2013, TTP was linked to the killing of 127 Christians in Peshawar.

Yet despite overwhelming evidence of the threat presented by TTP, Pakistan has been utterly deficient in dismantling it.

Neither a lack of resources nor a lack of international support is the problem. Pakistan has spent billions of dollars on its counterterrorism efforts, the bulk of which has come directly from the United States. U.S. drone attacks, meanwhile, have aided in the fight against TTP. And although Pakistan does, at the very least, turn a blind eye toward some terrorist groups that target India, that does not really figure into this case; the TTP mostly murders within Pakistan.

Rather, the problem is a group of draconian laws that a military dictator, Zia ul-Haq, enacted decades ago and a dangerous culture of impunity the laws have engendered. Known as the blasphemy laws, these provisions punish any “spoken, written, or visible representation,” including offense by “imputation, innuendo, or insinuation,” that “directly or indirectly defiles the sacred name of Prophet Muhammad” and thus outrages the religious sentiments of Muslims. The accused can face capital punishment. The codes thus provide legal cover for terrorists to commit atrocities in the name of protecting Islam’s integrity based on their warped view of the faith.

Since 1984, Pakistan has permitted the arrest and prosecution of several thousand of its citizens—both Muslim and non-Muslim­—on trivial and often trumped-up charges of blasphemy. These include wearing an Islamic slogan on a T-shirt, using an Islamic greeting in a public square, making the call for prayer on a loudspeaker, printing a wedding invitation card with Koranic verses, sending a text message perceived as critical of Islam, even committing a spelling error on an examination. And the registered cases prompt violence against the accused. For example, earlier this year, TTP sympathizers in Gujranwala burned down many homes in an Ahmadi-inhabited village over an allegedly blasphemous Facebook posting, killing four, including an elderly woman and her two young granddaughters. More troubling than these individual cases is the ability of groups like TTP to draw on the laws to justify their crimes.

For example, when TTP and its affiliates massacred Ahmadis and Christians, it claimed that it was doing so because Ahmadis and Christians are infidels who insult Islam. Similarly, when TTP massacred the children of military families last week, it claimed that it was to signal its opposition to the parents’ implicit support for U.S.-backed drone attacks. Here, too, TTP’s justification is apparent: silence those who threaten, however indirectly, Pakistan’s status as an Islamic state.

In all of this, TTP has the backing of laws that criminalize minority beliefs, views, and activities. Indeed, TTP has made fighting blasphemy its raison d’être. For example, in 2012, one TTP spokesperson rallied all Muslim youth of Pakistan to fight blasphemy, saying: “Zionist and crusader enemies of Islam are insulting the signs of Islam everywhere.” The approach has worked: feeling intimidated themselves, Pakistani authorities have failed to fully prosecute a single TTP or TTP-affiliated operator for any of the group’s prior attacks. Between arrest and conviction, the criminal cases against TTP and its affiliates drag, falter, and fold because police fail to furnish incriminating evidence and few lawyers or judges dare to confront the difficult question of limiting the reach of Pakistan’s blasphemy laws. It also does not help that lawyers who represent individuals accused of blasphemy are threatened and killed. For example, Rashid Rehman, a well-known civil rights advocate defending a blasphemy prosecution, was shot and killed in Multan last May.

Within the Pakistani government, the most vocal opponents of the blasphemy laws, Salman Taseer, the governor of Punjab, and Shahbaz Bhatti, the minister of minorities affairs, were assassinated. In Taseer’s case, the assassin, Mumtaz Qadri, maintained the support of over 500 Muslim clerics and was serenaded with rose petals and praised for his “defense” of Islam as he entered the court during his trial. A TTP spokesperson justifying Bhatti’s murder struck a similar note: “[The] assassination of Bhatti is a message to all of those who are against Pakistan’s blasphemy laws.”

If Pakistan is serious about ridding itself of TTP, it must do more than simply vow to up its war on terrorism. It must address the reasons that TTP can terrorize with impunity. It must examine and dismantle its own discriminatory penal code that has long suffocated the rights of citizens and protected terrorists. It must overcome a culture of fear that prevents adequate police protection for vulnerable populations and communities and robust prosecution of known terrorists. Above all, it must decide whether it is prepared to defeat the ideology, and not simply the weaponry, of its biggest enemy.