WICHITA, Kan. (AP) — A Mexican man living unlawfully in the United States for decades was arrested Tuesday in an identity theft scheme that was so ingenious that prosecutors say a court unwittingly changed the name of the U.S. citizen whose identity he assumed to his own real name.

The 33-count indictment outlining one of the most unusual identity theft cases in the country accuses 81-year-old Ramon Perez-Rivera of assuming a false identity to obtain food stamps and Medicaid, register to vote and obtain a U.S. passport and a driver's license.

Unsealed Tuesday in federal court in Wichita, the indictment against Perez-Rivera and his 82-year-old wife, Antonia Vargas-Ortega, outlines a sporadic history of unlawful entry into the United States that dates as far back as the 1950s. It offers a glimpse at an immigrant family's life in the shadows that spanned decades — and left in tatters the identity of the 86-year-old Arizona man whose identity was hijacked.

The government contends Perez-Rivera succeeded in fooling scores of state and federal agencies — with the exception of the times he tried to get Supplemental Social Security Income benefits from the Social Security Administration, where the scam finally unraveled.

Perez-Rivera faces a court appearance Wednesday on charges of aggravated identity theft as well as counts related to making false statements in order to obtain a passport, food stamps and Medicaid benefits as well as register to vote; lying to a federal agent; misusing a Social Security number to obtain a Kansas driver's license; and fraudulently attempting to get Social Security income benefits.

His wife, now a naturalized U.S. citizen, also faces charges that include aggravated identity theft, making a false statement to the Social Security Administration and harboring a person unlawfully in the United States. Court records do not indicate whether they have attorneys.

Assistant U.S. Attorney Brent Anderson, who has prosecuted hundreds of immigration-related cases, said he has never seen one in which a defendant allegedly changed the identity theft victim's name to his own name.

The couple settled in California around 1980. Immigration officials arrested Perez-Rivera in 1981 for being in the country unlawfully, but did not take his wife into custody because of three adolescent children in the home, according to the indictment. Instead of surrendering herself to immigration officials the next day as promised, she fled. Court documents not indicate the outcome of his arrest.

Federal prosecutors said the identity theft victim was born in California. He is identified in the indictment only as T.A.P.

The government contends that in 1996 Perez-Rivera filed a name change petition in Ventura County, California, Superior Court in which he falsely represented himself to be T.A.P. The court granted the petition and entered an order changing the name of T.A.P. to Ramon Perez-Rivera.

Perez-Rivera assumed the victim's Social Security number, date and place of birth, and at times even the names of T.A.P.'s parents, prosecutors say. He then used the court order to amend T.A.P.'s California birth record to reflect the change of name, according to the indictment. He was able to get the Social Security Administration to change the name on T.A.P.'s account and issue Perez-Rivera a Social Security card. By 1997, he had obtained a U.S. passport.

The family moved to Kansas in 1998, and the following year he began receiving Medicaid benefits and food stamps. He also registered to vote in Sedgwick County in 1999, and an online check by The Associated Press of voting records indicates he voted at least once, in the 2000 general election.

In June 2011, an investigator from the Social Security Administration interviewed Perez-Rivera and seized all his identity documents. He was not charged at the time. The government says Perez-Rivera got a new Kansas driver's license less than a month later by claiming he had lost his old one. Prosecutors say he tried in 2012 to replace the seized U.S. passport, falsely declaring again he was U.S. citizen. That time, his application was denied.