The bitter and bizarre feud between the federal government and the Church of Scientology took a startling turn last month when U.S. District Judge Charles R. Richey removed himself from presiding over a pending criminal trial of two members of the church. Richey claimed the defendants and their attorneys had engaged in "groundless and relentless" attacks on him. Presumably one of those attacks was a charge -- reported by columnist Jack Anderson -- that Richey purchased the services of a prostitute while in California to hear one aspect of the government's case against the Scientologists.

Richey would not comment on the report.

Behind the story of the Anderson column and Richey's decision was an elaborately staged undercover operation by a local private investigator, Dick Bast. Bast was hired by the Scientologists to learn, among other things, if the judge -- who last December sentenced some members of the church to prison for breaking into government offices to steal documents -- was predisposed to rule against the defendants because of a personal dislike for Scientologists. Along the way, Bast learned about the alleged liaison between Richey and a prostitute.

"First we had to penetrate the government people working on the case," says Bast, who claimed a whopping $321,000 fee (plus $84,000 in expenses) for masterminding the scheme.

Early this year Bast began to portray himself as a well-paid gumshoe for a wealthy European industrialist whose daughter had committed suicide shortly after joining the Scientologists. Bast roamed Europe, staying in first-class hotels, traveling to and from the continent on the Concorde, taking every opportunity to meet with law enforcement authorities. At each meeting he railed against the Scientologists, demanding to know what was being done to investigate the church.

In the U.S. he met with people who disliked the Scientologists, even putting a woman who had written a critical book about the church on his payroll. With his cover as a virulent anti-Scientologist intact, Bast eventually made his way into the Richey camp. His entree was provided by Jim Perry, one of the two U.S. marshals who accompanied Richey to Los Angeles last year when the judge ruled on one aspect of the government's case against the church.

A mutual friend brought Perry together with Bast by suggesting Bast might be able to help him obtan some disability pay Perry felt he was owed. Gradually Bast's conversations with Perry turned toward his nine years of work as a marshal. And when Perry mentioned he'd thought about writing a book about his experiences, Bast saw his opening. He paid Perry a $2,000 advance and signed a contract with him. Perry confirms receiving the payment. aHe also received expenses for traveling with Bast.

"I told Perry he'd have to put the good as well as the bad in the book to make it truthful," Bast recalls.

Perry and a Bast associate wearing a concealed tape recorder spent an evening reminiscing with another former assistant to Richey. Those hours of shoptalk led to mentions of prostitutes Richey allegedly entertained last year in Los Angeles. This summer, Bast (often with Perry along) worked to locate at least one prostitute. Perry thought the research was in aid of his book; Bast, of course, was in search of derogatory information about the judge for the Scientologists.

By the end of the caper, with the help of an off-duty Los Angeles police officer, a vice squad detective and four California private detectives, Bast located one hooker who recalled in detail her liaison with Richey. Bast, who says he paid the prostitute $300-a-day for her time, arranged for a lawyer to take a sworn statement while being videotaped in a rented television studio. t

It was from that information that Anderson wrote his column. For Richey, the Scientologists' crusade against him apparently proved too much, and citing "groundless and relentless" attacks against him, he resigned from the case in mid-July.