A man who helped write the computer code behind several U.S. lotteries, including some of its biggest, pleaded guilty Thursday to masterminding a scheme through which he rigged the winning numbers for jackpots in several states and collected millions of dollars.

Eddie Tipton, who worked for the Multi-State Lottery Association from 2003 until 2015 and was its computer information security director for his last two years there, appeared in a Des Moines courtroom, where he pleaded guilty to one count of ongoing criminal conduct and publicly acknowledged his lead role in the scheme for the first time.

"I wrote software that included code that allowed me to understand or technically predict winning numbers, and I gave those numbers to other individuals who then won the lottery and shared the winnings with me," Tipton said when asked by Judge Brad McCall to explain what he did.

Tipton, 54, said that when he wrote the code, he believed he was taking advantage of a loophole in the random number software and he didn't think it was illegal.

Investigators say Tipton installed code that let the computers work as should on all but three days of the year — May 27, Nov. 22 and Dec. 29 — when they would produce predictable numbers if the drawings occurred on Wednesdays or Saturdays after 8 p.m.

Tipton admitted in court that he provided cohorts with the winning numbers for jackpots in Colorado in 2005, Wisconsin in December of 2007, Kansas in December of 2010 and Oklahoma in 2011.

The group, which included Tipton's brother Tommy Tipton and a friend, Texas businessman Robert Rhodes, also attempted to collect a $16.5 million Hot Lotto ticket in December 2010 in Iowa, but Iowa lottery officials refused to pay it because the men tried to cash it anonymously. Iowa rules require the buyer and owner of the ticket to be made public.

That led to an investigation into a potential lottery fraud. Once Tipton was identified as a possible suspect, investigators began checking for connections to other winning games and zeroed in on winnings connected to Tipton, his brother, and Rhodes in the other states.

Tipton's plea deal resolves his legal situation in all of the affected states. He could get up to 25 years in prison when he's sentenced. A date hasn't been set and he remains free on bond.

Immediately after Tipton's hearing, his brother pleaded guilty to charges of conspiracy to commit theft by deception.

"My brother did provide me with numbers to play in Colorado and Oklahoma lotteries and he told me that it was illegal for him to play the lotteries but gave me the numbers to play," Tommy Tipton said.

Tipton, a 53-year-old former Texas magistrate judge and a law enforcement officer, said he's now unemployed and must sell part of his farm to pay the $800,000 in restitution that the judge ordered.

"That is financially effectively going to more than wipe him out," said his attorney, Mark Weinhardt. "Mr. Eddie Tipton does not have the resources to satisfy restitution in any meaningful degree. Mr. Tommy Tipton does and this will effectively take all of his assets."

Rob Sand, the assistant state attorney general who prosecuted the case, said after the hearing that it appears much of the stolen money is gone.

"As is the case in many financial crimes, the individuals who obtain the money usually spend it, thereafter leaving only margins of it to be recovered later. I think were in better shape in this case than we are in many cases, though," he said.

Sand said the scheme resulted in payouts of $2.2 million and he has demanded repayment through restitution from the Tipton brothers and Rhodes.

Rhodes, of Sugar Land, Texas, bought winning numbers for drawings in Colorado, Wisconsin, Iowa, Kansas, and Oklahoma between 2005 and 2011. He earlier pleaded guilty to being party to a computer crime and awaits sentencing.

Iowa Lottery CEO Terry Rich said information learned in the Tipton case has helped improve lottery security.

The scandal has led to a consumer fraud lawsuit against the Urbandale, Iowa-based Multi-State Lottery Association. The association serves lotteries in 33 states the District of Columbia, Puerto Rico and the U.S. Virgin Islands, and provides the computers used to randomly draw numbers in several games including Powerball, Mega Millions and Hot Lotto, among other games.

Sand said there's a simple moral to the story.

"Thou shall not steal," he said. "I mean small steps down a darkened path can lead a long way for somebody from where they think they're going to be from where they end up."