When the Iowa attorney general’s office began investigating an unclaimed lottery ticket worth millions, an incredible string of unlikely winners came to light - and a trail that pointed to an inside job.

The file landed on Rob Sand’s desk with something less than a thud. Despite holding the contents of an investigation still open after more than two years, the file was barely half an inch thick. “Happy birthday,” his boss said.

It was not Rob Sand’s birthday. His boss, an Iowa deputy attorney general named Thomas H. Miller, was retiring in July 2014 after nearly three decades of prosecuting everything from murder to fraud. He hired Sand about four years earlier and made him the youngest prosecutor in a nine-attorney team that handled challenging cases all over the state. Now Miller was offloading cases to colleagues. This one, having to do with a suspicious lottery ticket worth $16.5 million, was full of dead ends. Investigators didn’t even know if a crime had been committed. The most tantalizing pieces of evidence were on a DVD: two grainy surveillance clips from a gas station. Sand slid the disc into his laptop and pressed play.

A man walked into a QuikTrip convenience store just off Interstate 80 in Des Moines. It was a weekday afternoon, two days before Christmas. The hood of the man’s black sweatshirt was pulled over his head, obscuring his face from two surveillance cameras overhead. Under the hoodie, he appeared to be wearing a ball cap; over the hoodie, he wore a black jacket. The man grabbed a fountain drink and two hot dogs.

“Hello!” the cashier said brightly.

The man replied in a low-pitched drawl, a voice that struck Sand as distinct: “Hell-ooooh.”

“Couple hot dogs?” the cashier asked.

“Yes, sir,” the man replied quietly, his head down.

The man pulled two pieces of paper from his pocket. They were play slips for Hot Lotto, a Powerball-like lottery game available in 14 states and Washington, D.C. A player — or the game’s computer — picked five numbers between 1 and 39 and then a sixth number, known as the Hot Ball, between 1 and 19. The prize for getting the first five numbers right was $10,000. But a much larger prize that varied according to the number of players who bought tickets went to anyone who got all six numbers right. The record Hot Lotto jackpot of nearly $20 million had been claimed in 2007. The jackpot at the time of this video was approaching the record. The stated odds of winning it were one in 10,939,383.

The cashier took the man’s play slips, which had already been filled out with multiple sets of numbers. At 3:24 p.m., the cashier ran the slips through the lottery terminal. An older man with a cane limped by the refrigerated section. A bus drove by. The cashier handed over his change. Once outside, the man pulled down his hood and removed his cap, got into his S.U.V. and drove away. The gas-station parking lot gleamed; there had been snow flurries that afternoon.

Two years into the case, that was virtually all the investigators had. Sand watched the video again and again, trying to pick up every little detail: the S.U.V.’s make; the man’s indistinct appearance: most likely in his 40s, and 100 pounds overweight, maybe more; the tenor of his voice.

Sand, a baby-faced Iowan who turned down Harvard Law School for the University of Iowa College of Law, had a background that seemed perfect for the case: a high school job writing computer code and doing tech support, a specialty in white-collar crime. His recent cases included securities fraud and theft by public officials.

The ticket in the video was purchased on Dec. 23, 2010. Six days later, the winning Hot Lotto numbers were selected: 3, 12, 16, 26, 33, 11. The next day, the Iowa Lottery announced that a QuikTrip in Des Moines had sold the winning ticket. But one month after the numbers were drawn, no one had presented the ticket.

The Iowa Lottery held a news conference. Phone calls poured in; dozens of people claimed to be the winner. Some said they had lost the ticket. Others said it was stolen from them. But lottery officials had crucial evidence that wasn’t publicly available: the serial number on the winning ticket and the video of the man buying it. One by one, they crossed off prospective claimants. One caller said his friend was a regular Hot Lotto player who had just died in a car wreck — should he go to the junkyard to search through his deceased friend’s car?

Three months after the winning ticket was announced, the lottery issued another public reminder. Another followed at six months and again at nine months, each time warning that winners had one year to claim their money. “I was convinced it would never be claimed,” says Mary Neubauer, the Iowa Lottery’s vice president of external relations. Since 1999, she had dealt with around 200 people who had won more than $1 million; she’d never seen a winning million-dollar ticket go unclaimed. “And then comes Nov. 9, 2011.”

A man named Philip Johnston, a lawyer from Quebec, called the Iowa Lottery and gave Neubauer the correct 15-digit serial number on the winning Hot Lotto ticket. Neubauer asked his age — in his 60s, he said — and what he was wearing when he purchased the ticket. His description, a sports coat and gray flannel dress pants, did not match the QuikTrip video. Then, in a subsequent call, the man admitted he had “fibbed”; he said he was helping a client claim the ticket so the client wouldn’t be identified.

This was against the Iowa Lottery rules, which require the identities of winners to be public. Johnston floated the possibility of withdrawing his claim. Neubauer was suspicious: The winner’s anonymity was worth $16.5 million?

One year to the day after the winning numbers popped up on the random-number-generator computers — and less than two hours before the 4 p.m. deadline — representatives from a prominent Des Moines law firm showed up at the Iowa Lottery’s headquarters with the winning ticket. The firm was claiming the ticket on behalf of a trust. Later, the Iowa Lottery learned that the trust’s beneficiary was a corporation in Belize whose president was Philip Johnston, the Canadian attorney. “It just absolutely stunk all over the place,” says Terry Rich, chief executive of the Iowa Lottery. The Iowa attorney general’s office and the Iowa Division of Criminal Investigation opened a case.

In an interview in Quebec City, Johnston told investigators that he had been contacted about the ticket by a Houston attorney named Robert Sonfield. Johnston also pointed investigators toward a Sugar Land, Tex., businessman named Robert Rhodes. A trip to Texas by Iowa investigators proved fruitless; during their several days there, both Sonfield and Rhodes managed to avoid them.

By the time the file ended up on the desk of Rob Sand in 2014, the case had acquired cultlike status in his office. It was spoken about with gallows humor: “We’ll find the guy who bought the ticket ended up getting offed,” Sand said. “That’s what this is going to turn out to be, a murder case.”

Miller had mentored Sand and saw in him a kindred spirit, someone for whom practicing law was a calling. Sometimes Sand’s moral compass was so steady that he came off as a square; his brothers-in-law nicknamed him Baby Jesus. Sand grew up in Decorah, in northeast Iowa, the son of a small-town doctor who still made house calls. He wanted to get into white-collar criminal prosecution because it focused not on crimes of desperation but on crimes of greed. “Crimes against gratitude,” Sand called them.

But all he had was grainy video of a man buying a lottery ticket worth $16.5 million. “We only had one bullet left in our revolver,” Sand says, “and that was releasing the video.”

On Oct. 9, 2014, nearly 46 months after the man in the hoodie left the QuikTrip, the Iowa Division of Criminal Investigation put out a news release that included a link to a 74-second clip of the surveillance footage. A few days later, in Maine, an employee of the Maine Lottery opened an email forwarded from his boss. The employee recognized the distinct voice in the video: It belonged to a man who had spent a week in the Maine Lottery offices a few years earlier conducting a security audit.

In Des Moines, a web developer at the Iowa Lottery who watched the video also recognized that voice: It belonged to a man she had worked alongside for years. A receptionist in another lottery office handed her earbuds to Noelle Krueger, a draw manager, and told her to listen. “Why am I listening to a video or listening to a tape of Eddie?” Krueger replied.

The file landed on Rob Sand’s desk with something less than a thud. Despite holding the contents of an investigation still open after more than two years, the file was barely half an inch thick. ‘Happy birthday,’ his boss said. It was not Sand’s birthday. Illustration by Francesco Francavilla

By Eddie, she meant Eddie Tipton, the information-security director for the Multi-State Lottery Association. The organization runs lotteries for 33 different states plus the District of Columbia, Puerto Rico and the U.S. Virgin Islands. It was based in the Des Moines suburbs. Among the games it ran was the Hot Lotto.

Eddie Tipton cut a big, friendly figure around the office of the Multi-State Lottery Association. He grew up in rural Texas, but while his siblings were outside, he was always in his room, fiddling with his computer. He was a paranoid sort who rarely paid with credit cards, who worried about people tracing his identity. But he always wanted people to like him. When a co-worker was in a bad mood, one colleague said, Tipton would pat him on the shoulder and say, “I just want you to know I’m your friend.”

Tipton built a 4,800-square-foot, $540,000 house in the cornfields south of Des Moines. The house had five bedrooms and a huge basement, including a pool table, a shuffleboard table, a stadium-style home theater with couches and a space he considered turning into a basketball court. Friends wondered why a single man needed such a big house and how he could afford it on a salary just shy of $100,000 a year. In private moments, Tipton told them he was lonely and wanted a family more than anything, so he poured his savings into the house he hoped to fill with a wife and children. But the right partner never came. Instead, he hosted office Christmas parties, and he constantly asked friends to visit. His family, still in Texas, checked on him frequently.

His life revolved around his job. The Multi-State Lottery Association was a small organization, and Tipton felt overextended. He wrote software and worked on web pages. He handled network security and firewalls. And he reviewed security for lottery games in nearly three dozen states. He was putting in 60-hour weeks and staying at the office until 11 p.m.

When Ed Stefan, the chief information officer and chief security officer at the Multi-State Lottery Association, saw the surveillance video, he didn’t want to believe it. This wasn’t just some co-worker. This was Eddie Tipton, a man he had known for more than two decades, since they were in calculus class at the University of Houston. Stefan met his future wife while he and Tipton were on a charity bike ride in Texas; Tipton would later be in their wedding. Stefan helped Tipton get his job at the association. They bought some 50 acres of land together and built adjacent houses. They even applied for a joint patent for computer-based lottery security.

Stefan watched the convenience-store video for the first time after a former co-worker sent him the link that had been released by prosecutors. That just can’t be Eddie, he thought. Then: That’s Eddie. Why is he wearing a hoodie? I’ve never seen Eddie in a hoodie. Stefan got sick to his stomach: His friend, a man with deep knowledge of the computers that ran the lottery, was there onscreen buying a ticket that would be worth $16.5 million. Later, Stefan would tell investigators it was like finding out your mother was an ax murderer. He felt betrayed.

Jason Maher was another friend and colleague who didn’t want to believe what he was seeing on the video. He and Tipton had met at Taki, a Japanese restaurant outside Des Moines that they both frequented. The lifelong computer aficionados and gamers hit it off; Tipton joined Maher’s gaming clan, and they spent hours playing the multiplayer online game World of Tanks. Tipton suggested Maher apply for a job at the lottery association as a network engineer. Tipton, Maher told me, “had a heart of gold.”

So when Maher saw the video and heard that familiar low-pitched voice, he did what a computer whiz does. “That night I sat down — there’s no way Eddie did this,” Maher said. “There’s got to be something wrong.” He put the file of the surveillance tape into audio software, removed white noise and isolated the voice. Then he took footage from security cameras in his house — Tipton had just visited the night before — and compared Tipton’s voice in that footage with the convenience-store video. “It was a complete and utter match, sound wave and everything,” Maher said. The next day, he went to the QuikTrip where the ticket was purchased and measured the dimensions of the tiles on the floor, the height of the shelving units, the distance between the door and the cash register. He used the results to compare the hand size, foot size and height of the man in the video with the man he had become friends with.

“When the F.B.I. guys came in, I wanted to be able to tell them it wasn’t Eddie,” Maher said. “Once I did this, it was like, ‘Well, [expletive] — it’s Eddie.’ ”

In November 2014, state investigators showed up at Tipton’s office. They asked him whom he knew in Houston. He told them about his family — mother, sister and brothers, including Tommy, a former sheriff’s deputy turned justice of the peace near the Texas Hill Country. He did not mention Robert Rhodes, the man who initially passed the $16.5 million ticket to an attorney. By searching Tipton’s LinkedIn profile, investigators found that Tipton had been employed at Rhodes’s Texas-based software company, Systems Evolution, for six years as its chief operations officer. In fact, the two were best friends and vacationed together.

Tipton was arrested in January 2015 and charged with two felony counts of fraud. Half a year later, on a hot, sticky July morning, Rob Sand stood before a jury at the Polk County Courthouse. “This is a classic story about an inside job,” he began. “A man who by virtue of his employment is not allowed to play the lottery, nor allowed to win, buys a lottery ticket, wins and passes the ticket along to friends to be claimed by someone unconnected to him. This story, though, has a 21st-century twist.”

The prosecution knew Tipton had bought the winning ticket. The video, specifically the distinct voice that colleagues had recognized, made that pretty clear. So did cellphone records, which showed Tipton was in town that day, not out of town for the holidays as he claimed, and that he had been on the phone for 71 minutes with Robert Rhodes, the man who briefly had possession of the ticket. Investigators believed he’d fixed the lottery. But how?

Jason Maher, Tipton’s gaming buddy, told them about Tipton’s interest in rootkits: malicious software that can be installed via flash drive in order to take control of a computer while masking its existence until it deletes itself later. Sand theorized that Tipton went into the draw room six weeks before the big jackpot and, despite the presence of two colleagues, managed to insert a thumb drive into one of the two computers that select the winning numbers. That thumb drive contained the rootkit; the rootkit allowed Tipton to direct which numbers would win the Hot Lotto on Dec. 29, 2010.

Tipton’s defense attorney, Dean Stowers, called this the “Mission: Impossible” theory. Stowers characterized the story of a malicious, self-destructing rootkit (“magic software”), installed while two colleagues looked on, as preposterous. His closing arguments referenced a quotation attributed to Albert Einstein: “Logic will get you from A to B. Imagination will take you anywhere.”

But Sand called Stowers’s focus on this complicated rootkit theory a red herring. Sand told the jury to focus on the many ways Tipton could have fixed the lottery: He wrote the code. He had access to the random-number-generator machines before they were shipped to other states. You don’t have to understand the exact technology to convict Tipton, Sand argued; you just have to realize the near-impossible coincidence of the lottery security chief’s buying a winning ticket and that ticket’s being passed to his best friend. The prosecution had to prove only that Tipton tried to illegally buy lottery tickets as a Multi-State Lottery Association employee and tried to claim the prize through fraudulent means.

The jury found him guilty on July 20, 2015. He would be sentenced to 10 years in prison, and he would appeal. The State Supreme Court later dismissed his conviction on one charge, tampering with lottery equipment, and the case was sent back to District Court.

Six weeks after the trial concluded, Sand had returned to his desk. It had been a busy summer. But in the back of his mind, he was still thinking about Eddie Tipton. Sand knew white-collar criminals aren’t usually caught on their first attempt. The fact that Tipton’s attorney had demanded a 90-day speedy trial, an unusual maneuver that cut short the prosecution’s time to investigate, made Sand suspicious. His gut said other fraudulent lottery tickets were out there.

One morning Sand’s office phone rang, and an area code he recognized popped up: 281, from Texas, where Tipton used to live. Sand picked up. The caller had a drawl and told Sand he’d seen an article in the La Grange, Tex., newspaper about Tipton’s conviction. “Did y’all know,” the tipster asked, “that Eddie’s brother Tommy Tipton won the lottery, maybe about 10 years back?”

Richard Rennison’s phone rang at the F.B.I. office in Texas City, a port town on the shore of Galveston Bay. Sand was on the line, inquiring about a case that Rennison, a special agent for the bureau, investigated a decade before. At the time, it turned out to be nothing. But the case still stuck in Rennison’s mind. “Hey,” Rennison replied, “that’s my Bigfoot case.”

A man named Tom Bargas had contacted local law-enforcement authorities in early 2006 with a suspicious story. Bargas owned 44 fireworks stands in Texas. Twice a year — after the Fourth of July and after New Year’s — he had to handle enormous amounts of cash, more than a half-million dollars at once. A local justice of the peace who shod Bargas’s horses called him around New Year’s. The justice of the peace caught Bargas off guard: “I got half a million in cash that I want to swap with your money.” “What’s wrong with your money?” Bargas replied.

All the prosecutor had was grainy video of a man buying a lottery ticket worth $16.5 million. ‘We only had one bullet left in our revolver,’ Sand says, ‘and that was releasing the video.’ Illustration by Francesco Francavilla

What’s a justice of the peace who makes around $35,000 a year doing with that much cash? Bargas thought. He called the sheriff and the police, who called the F.B.I. Soon, the bureau contacted Bargas. Federal agents outfitted him with a wire. Bargas met with the man, who pulled out a briefcase filled with $450,000 in cash, still in their Federal Reserve wrappers. As the F.B.I. listened, Bargas swapped $100,000 of worn, circulated bills for $100,000 of the man’s crisp, unused bills. To the F.B.I., this smelled like public corruption, and they went to work investigating the serial numbers on the bills.

One day a couple of months later, Rennison got a call from the Fayette County sheriff in La Grange, a place best known for the Chicken Ranch, the brothel that inspired “The Best Little Whorehouse in Texas.” The sheriff was laughing so hard he could hardly speak. He told Rennison the justice of the peace was holed up in a Houston hospital with two shattered legs. He had fallen 31 feet out of a tree. He had been hunting Bigfoot.

“My grandmother was raised on a farm in Arkansas where this creature would come in and harass all the farm animals,” this man later told investigators. “My grandmother would tell me all these stories of this animal that harassed my family.” He went on: “I started hitting the woods. It was always that doubt in your mind. And then something happened to me in Louisiana where I actually watched these animals for a couple of hours, and I’ve been hooked ever since.”

Rennison visited the man in the hospital and then set up an interview once he was discharged. The man was a member of the Bigfoot Field Researchers Organization. He told Rennison he’d won the lottery in Colorado while on a Bigfoot hunt. He was on the outs with his wife and was trying to keep the lottery winnings from her. A Bigfoot-hunting friend claimed the prize in exchange for 10 percent of the money. It all checked out. Case closed.

“Right before I leave, we’re still sitting down at this nice conference table, and he looks over at his attorneys and says, ‘Can I show him?’ ” Rennison recalled. “Hanging off the back of his chair is a plastic grocery bag. He pulls out a plaster cast of a footprint.”

Rennison put the footprint next to his own foot. They were roughly the same size. “That doesn’t look like Bigfoot,” the F.B.I. agent said. “It was a juvenile,” the man snapped. The man’s name was Tommy Tipton.

Now the hunt was on for more illicitly claimed tickets. Iowa investigators noticed that the friend who claimed the $568,990 Colorado Lottery prize for Tommy Tipton, a man named Alexander Hicks, was dead. “We first thought, Whoa — this is our first body related to this case,” Sand says. It wasn’t. Hicks had died of cancer.

The investigators collected a decade’s worth of winners from lotteries around the country associated with the Multi-State Lottery Association. They loaded data from approximately 45,000 winning tickets into Microsoft Excel spreadsheets and searched for any connections to Eddie Tipton. They reviewed Tipton’s Facebook friends, pulled phone records and looked for matches with the spreadsheet.

In September 2015, they learned that a $783,257.72 payout for Wisconsin’s Very Own Megabucks Game had been claimed in early 2008 by a Texas man named Robert Rhodes, who wanted to deposit it into the account of a limited-liability corporation. That drawing took place on Dec. 29, 2007 — the same day the winning numbers on Tipton’s $16.5 million Iowa ticket were selected three years later. Rhodes was Eddie Tipton’s best friend. Another hit.

One evening over the holidays, Sand was at his parents’ house working on his laptop, sifting through records, using search commands on his computer again and again. He noticed that a Kyle Conn from Hemphill, Tex., won a $644,478 jackpot in the Oklahoma Lottery some years back. Tommy Tipton had three Facebook friends named Conn. Sand got a list of possible phone numbers for a Kyle Conn and cross-referenced them with Tommy Tipton’s cellphone records. Another hit.

Investigators noticed two winning Kansas Lottery tickets for $15,402 apiece were purchased on Dec. 23, 2010 — the same day Tipton had purchased the Iowa ticket, and the same day that cellphone records indicated he was driving through Kansas on the way to Texas for the holidays. One of the winning tickets was claimed by a Texan named Christopher McCoulskey, the other by an Iowa woman named Amy Warrick. Each was a friend of Eddie Tipton’s.

Early one morning, Sand and an investigator knocked on the woman’s door. She told them she’d gone on one date with Tipton, but their relationship became platonic. Tipton told her he wasn’t able to claim a winning lottery ticket because of his job. If she could claim it, Tipton said, she could keep a significant portion as a gift for her recent engagement.

“You have these honest dupes,” Sand says. “All these people are being offered thousands of dollars for doing something that’s a little bit sneaky but not illegal.” Investigators in Iowa now had six tickets they figured were part of a bigger scam. But the question remained: How did it work?

Investigators in Wisconsin discovered they still had the random-number-generator computers used for the 2007 jackpot sitting in storage. Unlike Iowa’s computers, the hard drives had not been wiped clean; their software was the same as the day Robert Rhodes won $783,257.72. Wisconsin enlisted a computer expert named Sean McLinden to conduct an investigation that included forensic analysis and reverse engineering.

On Jan. 7, 2016, Sand’s phone rang. It was David Maas, an assistant attorney general in Wisconsin. He told Sand to check his email. Maas had sent him an attachment with 21 lines of “pseudocode,” a common-language translation of McLinden’s forensic analysis that showed part of Tipton’s malicious computer code. The code was small enough that it would not radically change the size of the file, which might create suspicion. And the code hadn’t been hidden. You just needed to know what to look for.

“This,” Maas says, “was finding the smoking gun.”

The smoking gun would help lead to a guilty plea from Tipton. In the plea deal, Sand insisted that Tipton come clean about how he fixed the lottery. This could help the lottery industry improve its security. If Tipton lied — or if another fraudulent ticket were found later — the deal would be voided, and Tipton would be subject to further charges.

Tipton’s program was called QVRNG.dll: Quantum Vision Random Number Generator. In Tipton’s telling, his wasn’t an evil plan to get rich. This was just a computer nerd’s attempt to crack the system. “It was never my intent to start a full-out ticket scam,” Tipton told investigators. “It occurred to me, like, Wow, I could do this, I could be making a living doing this.” He went on: “If this was, like, some mob-related thing, I’d just give this information to the mob and they would go out and win the lotteries left and right. Nobody would know. But that — I don’t have any mob ties. I don’t know anybody. I gave tickets to friends or family.”

More than a decade ago, Tipton told them, he walked past one of the organization’s accountants at the Multi-State Lottery Association. Tipton was conservative, the accountant liberal, and they often ribbed each other.

“Hey, did you put your secret numbers in there?” the accountant said, teasing Tipton.

“What do you mean?”

“Well, you know, you can set numbers on any given day since you wrote the software.”

And that’s when the idea first came. “Just like a little seed that was planted,” Tipton said in his proffer. “And then during one slow period I just had a — had a thought that it’s possible, and I tried it and I put it in.” The code wasn’t a brazen “Mission: Impossible” stunt of sneaking into the draw room with a malicious thumb drive. It was a simple piece of code, partly copied from an internet source, inserted by the one man responsible for information security at an organization that runs three dozen United States lotteries.

The code was small enough that it would not radically change the size of the file, which might create suspicion. And the code hadn’t been hidden. You just needed to know what to look for. ‘This,’ David Maas, an assistant attorney general in Wisconsin, says, ‘was finding the smoking gun.’ Illustration by Francesco Francavilla

Here’s how the Multi-State Lottery Association’s random-number generators were supposed to work: The computer takes a reading from a Geiger counter that measures radiation in the surrounding air, specifically the radioactive isotope Americium-241. The reading is expressed as a long number of code; that number gives the generator its true randomness. The random number is called the seed, and the seed is plugged into the algorithm, a pseudorandom number generator called the Mersenne Twister. At the end, the computer spits out the winning lottery numbers.

Tipton’s extra lines of code first checked to see if the coming lottery drawing fulfilled Tipton’s narrow circumstances. It had to be on a Wednesday or a Saturday evening, and one of three dates in a nonleap year: the 147th day of the year (May 27), the 327th day (Nov. 23) or the 363rd day (Dec. 29). Investigators noticed those dates generally fell around holidays — Memorial Day, Thanksgiving and Christmas — when Tipton was often on vacation. If those criteria were satisfied, the random-number generator was diverted to a different track. Instead, the algorithm would use a predetermined seed number that restricted the pool of potential winning numbers to a much smaller, predictable set of numbers.

So Tipton knew what no one else knew: For the Iowa Hot Lotto drawing on Dec. 29, 2010, there weren’t really 10,939,383 sets of possible winning numbers. There were only a few hundred. Late at night before a draw that fulfilled his criteria, Tipton stayed in his messy, computer-filled office. He set a test computer to the date and time of the coming draw, and he ran the program over and over again. For the first lottery he rigged, the Nov. 23, 2005, drawing in Colorado, Tipton wrote down each potential set of winning numbers on a yellow legal pad. He handed the pad — each sheet had 35 or so sets of six numbers — to his brother.

It was a cheat sheet; instead of playing every possible number combination to ensure one combination won, he had to play only a few hundred. “If you want a chance to win, you need to play all of these,” Tipton told his brother. “I don’t know if any of them will win, but you’re going anyway” — his brother was about to go on a Bigfoot-hunting trip to Colorado — and “these have a good chance of winning based on my analysis.

“Play them,” he said. “Play them all.”

On a clear, blue summer day in Des Moines last year, Eddie Tipton, a square-shaped, balding man who was then 54, trudged up the stairs of the Polk County Courthouse. He wore bluejeans and a short-sleeved salmon-colored button-up shirt, untucked and unbuttoned, with a blue T-shirt underneath. His hands were shoved in his pockets, and his head was down. He had accepted a plea agreement for masterminding the largest lottery scam in American history: one count of ongoing criminal conduct, part of a package deal that allowed his brother to be sentenced to only 75 days. Tipton was here for his sentencing.

In statements to prosecutors, Tipton painted himself in the most generous way possible, a kind of coding Robin Hood, stealing from the lottery and helping people in need: his brother who had five daughters, his friend who’d just gotten engaged. “I didn’t really need the money,” Tipton said. The judge noted that Tipton seemed to rationalize his actions — that Tipton didn’t think it was necessarily illegal, just a taking advantage of a hole in the lottery’s system. It wasn’t all that different, Tipton believed, from insider trading, except laws didn’t specifically prohibit him from fiddling with the random-number-generator code. His attorney equated what he did with counting cards at a casino. Tipton wasn’t robbing the casino at gunpoint; he was cheating the house.

The other side disagreed. Tipton was “nothing but a common thief who happened to be handed the keys to the candy store,” Miller, Sand’s former boss, told me. “It’s not a case of Sherlock Holmes’s archnemesis, Moriarty, being a criminal genius. This is just a regular schlub, who is a thief who happens to have knowledge of computer security.”

From Tipton’s point of view, it was complicated. He had done something to see if he could do it. To his surprise, it worked. He said he inserted that code only once; after the code was approved by Gaming Laboratories International, machines containing it were shipped all over the country. He had created a beast and sent it into the world. “You plant that money tree in your backyard,” as Maas, the Wisconsin prosecutor, put it, “and it’s hard not to keep picking at it.”

In interviews, investigators had asked Tipton if he was proud of the success of his code. “It was more like I’m ready for it to be gone,” Tipton said. “It was never my intent to go out there and start winning all these lotteries. It was just, like I said, step by step it happened.”

At sentencing, the judge asked if Tipton had anything to say. After a long pause, Tipton cleared his throat. Family members and former co-workers were in the courtroom. “Well,” Tipton said matter-of-factly, “I certainly regret my actions. It’s difficult to say that with all the people behind me that I hurt. And I regret it. I’m sorry.” As the case was being litigated, Tipton had confessed to friends that he was racked with guilt. At another point during the proceedings, Tipton leaned across a divide and extended his hand to Sand. Sand took the handshake as a sign of respect, as if Tipton had thought he outsmarted the system but the system figured him out. On the day of his sentencing, Tipton told the judge he’d been taking classes to go into ministry. A deputy placed Tipton in handcuffs and led him away.

Earlier in the summer, Tipton sat in a conference room with Sand and law-enforcement and lottery officials to give his full confession, as promised in his plea agreement. Eventually he would head to Clarinda Correctional Facility in southern Iowa, near the Missouri border, where he remains today, Offender No. 6832975. (Through his attorney, he declined interview requests for this article; Tipton did not respond to nearly a dozen emails through the prison email system.)

During a lunch break in Tipton’s hourslong confession, Sand and others involved in the prosecution walked a few blocks to the High Life Lounge. They ordered bacon-wrapped tater tots to celebrate. “Eddie sees himself as much brighter than the rest of the world, the sharpest tool in the toolbox,” Sand says. “It’s the kind of thing I see in white-collar case after white-collar case, people who think they’re better than everybody else, that people trust them and love them, and that no one will be able to figure this out.”

The judge sentenced Tipton to a maximum of 25 years in prison. His restitution payments to the various state lotteries came to $2.2 million even though, according to his attorney, Tipton pocketed only around $350,000 from the scam, the rest going to those who claimed the tickets. (Prosecutors did not believe that, pointing to Tipton’s massive house as well as the fact that Tipton and his brother owned 11 pieces of property either jointly or individually in Fayette County, Tex.) In Iowa, which has indeterminate sentencing, a 25-year sentence could mean Tipton is released much sooner; Sand expects Tipton to be released by the Iowa Board of Parole within seven years.

Sand says he felt a deep intellectual satisfaction in solving the puzzle: “The justice system at its best is really about a search for truth.” But it couldn’t go back in time and correct wrongs. At the end of this yearslong case, he came to a realization: He had grown weary of dealing with criminals. “In so much darkness,” Sand says, “I started to lose my light.”

A few months after the highest-profile case of his career, Sand went up to his boss and quit. He had decided to run for state auditor in the coming November election, so he could make positive changes. If he wins, he will be investigating government waste, abuse and fraud. “There’s no way I would make a move to get away from the darkness of prosecution without finishing this case first,” Sand says. “So finishing it, to me, was not merely satisfying. It was liberating.”