CAIRO, Oct 6 - Sarah Hegazy has been jailed, beaten by inmates, and could face a life sentence in an Egyptian prison if found guilty of "promoting sexual deviancy" and other charges tied to her alleged crime: waving a rainbow flag at a concert.

The 28-year-old denies waving the flag but is one of 57 people arrested so far in Egypt's widest anti-gay crackdown yet, a swift zero-tolerance response to a rare show of public support for lesbian, gay, bisexual and transgender rights in the conservative Muslim country.

The crackdown comes as Egypt, a key Western ally in the Middle East, is under fire for its human rights record and the United States has withheld some of its $1.3 billion in annual military aid.

Hegazy, the only woman rounded up in the three-week-old campaign, says police goaded her cellmates to abuse her during her first night in prison, where she is being detained for 15 days and interrogated by special prosecutors who usually focus on Islamist militants.

"This is the game they (police) always play, especially since she is a girl. They incite the other detainees and say 'this girl wants men and women to be gay' so they harass her. I saw scratches on her shoulder, she looked very dishevelled and exhausted. She was beaten," said Hegazy's lawyer Hoda Nasralla.

"We're not talking about gay rights here, no one is calling for marriage equality, we face the possibility of jail and humiliation for merely existing."

A security official would not comment on Hegazy's case but denied that police incite prisoners against each other or otherwise mistreat them.

Lawyers for other detainees said their clients faced similar treatment. Suspected gay male detainees are subject to forced anal exams to determine if they have had homosexual sex, a procedure human rights groups say amounts to torture.

At least five such examinations have taken place, Amnesty International says. Judicial sources do not deny the examinations take place but say they are legally carried out and are not a form of abuse.

Egyptian authorities do not deny going after gays and an investigation report provided to Reuters by the Egyptian Initiative for Personal Rights (EIPR) openly refers to the police's campaign against gay people.

Police, state-aligned media, and the religious establishment all see it as a public duty to combat the spread of homosexuality.

Ten men have already gone on trial during the recent sweep and received jail sentences from one to six years.

Media Backlash

On Sept. 22, at a concert packed with 30,000 people headlined by Mashrou' Leila, a Lebanese alternative rock band whose lead singer is openly gay, a small group of concertgoers raised a rainbow flag and, within hours, the image went viral.

Almost immediately, local media, dominated by state-aligned television personalities, began a campaign against gays, saying they were receiving foreign funding, and hosting callers who compared their threat to Islamic State.

Egypt's media regulator then banned gay people people from appearing in the media unless they were "repenting," calling homosexuality a "shame and a disease that should be kept under wraps, not promoted" in order to protect public morality.

The Morning Rundown Let our news meet your inbox. The news and stories that matters, delivered weekday mornings. This site is protected by recaptcha

Al-Azhar, Egypt's 1,000-year-old centre of Islamic learning, said it would stand against gays in the way it stands against Islamist extremists. One church organised an anti-gay conference.

Public Prosecutor Nabil Sadek ordered the State Security Prosecution, which normally investigates terrorism and other national security threats, to investigate the flag incident.

At least four people, including Hegazy and 21-year-old Ahmed Alaa, were arrested for allegedly raising the flag although one man has since been released.

The overwhelming majority of those arrested are not involved in the flag case, however, and have simply been arrested over their perceived sexual orientation in the following days.

Police have raided homes, parties, and used online dating apps to lure gay men -- a common tactic in Egypt -- to arrest most of them, their lawyers say.

At a Cairo courthouse defendants stood in a cage, holding up newspapers and books to hide their faces to shield themselves from the stigma of homosexuality in Egyptian society.

Worst Crackdown Yet

Although homosexuality is not specifically outlawed in Egypt, it is a conservative society and discrimination is rife. Gay men are frequently arrested and typically charged with debauchery, immorality or blasphemy.

The last comparable crackdown on homosexuals in Egypt was in 2001, when police raided a floating disco called the Queen Boat. Fifty-two men were tried in the case, which drew widespread criticism from human rights groups and Western governments.

But the current wave has already surpassed that incident both in numbers and in state action, with defendants facing much faster trials than usual, said Dalia Abd Elhameed, EIPR's gender and women's rights officer.

No Western government has publicly condemned or commented on this crackdown, but Egypt is facing criticism from the United States, a major ally, over its human rights record.

Washington denied Egypt $95.7 million in aid and delayed a further $195 million because it failed to make progress on human rights and democracy, U.S. sources told Reuters in August.

Egypt has taken a leading role at the United Nations in opposing gay rights. It was one of 13 countries to vote last week against a U.N. resolution condemning the death penalty for having gay sex.

It led a dozen states in boycotting a session in January with the first U.N. expert on anti-gay violence and discrimination. It sent a letter last year on behalf of Muslim countries to the secretary-general that led to the exclusion of 22 gay and transgender rights groups from the U.N. General Assembly's High Level Meeting on Ending Aids.

Gay men and rights activists say the LGBTQ community has been facing an aggressive crackdown since 2013, when President Abdel Fattah al-Sisi as military chief ousted Muslim Brotherhood president Mohamed Mursi.

EIPR has documented 232 cases between October 2013 and March 2017 where people were arrested for allegedly being gay or transgender, Abd Elhameed said. Many of these cases went to court where the average sentence was around three years in jail, although in some cases it went up to 12.

Sisi has been criticised by the Brotherhood as being anti-Islam, and rights groups say tough treatment of the LGBT community is a way to counter that while diverting attention from the country's tough economic conditions.

Community in Fear

The crackdown has Egypt's already underground LGBTQ community living in fear. Five gay men who all requested anonymity said they were avoiding gay-friendly spaces and deleting online dating profiles for fear of arrest.

Some are considering leaving the country.

But the recent developments underscore an existing reality for gay Egyptians: They are in constant physical danger.

"I don't feel comfortable just being myself. We're not talking about gay rights here, no one is calling for marriage equality, we face the possibility of jail and humiliation for merely existing," said one 25-year-old gay man.

A 31-year-old gay man recounted how he was tied up and beaten at his Cairo flat last year by two men who threatened to kill him after meeting through the gay dating app Grindr.

They posed as police officers at some point, playing on a common fear for gay Egyptians, before stealing items from his flat. The man says he later felt going to the police was almost as traumatic as the incident itself.

Police records show officers create false dating profiles and set up dates only to arrest the men who show up. Sometimes they tell the men to bring condoms then use them as evidence, Abd Elhameed said.

"There are people in the Interior Ministry who take our money as taxpayers to engage in sex chatting with people then arrest them. It is as ridiculous as this; the evidence sheets include nude photos and erotic chat transcripts."

FOLLOW NBC OUT ON TWITTER, FACEBOOK AND INSTAGRAM