Diogenes had it easy, compared to the voters of Pennsylvania, in the search for an honest man.

In the last eight years, according to one calculation, 239 public officials have been indicted for crimes against the public trust.

Tuesday's primary presents 31 candidates for governor and lieutenant governor on the Democratic and Republican tickets. The leading hopefuls are former prosecutors, and the ones who are not sound like they should have been.

In a contest where the dominant style is to speak with conviction of the need for more convictions, one Republican in a recent television debate was moved to say that the first duty of the new governor will be not to send someone to jail but to prepare a new budget.

His rivals all agreed privately that he had muffed his chance.

But few observers are willing to bet much on who will survive among the four Republicans and three Democrats given a real chance of winning the nominations to succeed Gov. Milton J. Shapp (D). As Shapp's two terms end, no fewer than 60 legislators, state employes and administration appointees are in jail or under indictment.

The leading Democratic contenders are:

Lt. Gov. Ernest P. Kline, who though part of the Shapp administration and beneficiary of the state employes' political organization, has been as outspoken as anyone in denouncing the corruption in Harrisburg.

Former state auditor Robert P. Casey, who twice lost to Shapp in gubernatorial primaries and claims to have been the first to blow the whistle on corrupt Harrisbury practices.

Former Pittsburgh mayor Pete Flaherty, a longtime foe of Shapp, who served for a year as President Carter's deputy attorney general before entering this campaign.

On the Republican site, the lineup is even more prosecutorial. There are:

Robert J. Butera, minority leader of the state house of representatives, who says he has fought Shapp "every day for the last eight years," but erred - in his opponents' eyes - by talking too much about the budget in their televised debate.

Arlen Specter, the former Philadelphia district attorney, who claims to have "taken on the crooks in Pennsylvania's toughest city."

Richard L. Thornburgh, former U.S. attorney in Pittsburgh and assistant attorney general in the Ford administration, who claims to have brought the first indictment against a Shapp official.

David W. Marston, who won instant and enduring fame when he was ousted by Carter as U.S. attorney in Philadelphia after sending several Harrisbury officials to jail and launching an investigation of two Pennsylvania congressmen.

Marston vs. Thornburgh is more than a battle between two prosecutors from opposite ends of the state. It is a proxy war between two nationally ambitious Republican senators, Richard S. Schweiker and H. John Heinz III.

Schweiker has been out campaigning with Marston, who was an aide to the senator before Schweiker got him appointed U.S. attorney in 1976.

And Heinz has been stumping and doing television commercials with Thornburgh, an old friend from Pittsburgh and political ally.

The wealthy, polished Heinz was encouraging speculation about his ambitions for the national GOP ticket even when he was in the House of Representatives. In 1976 he took his first steps upward when he beat Specter in a bitter primary and went on to succeed Republican Hugh Scott in the Senate.

But Schweiker beat Heinz to the draw that same year by breaking ranks with Pennsylvania's pro-Jerry Ford Republicans and signing on as running-mate with Ronald Reagan, just before the GOP convention.

When Reagan lost his bid, Schweiker was blocked, but it was clear that the Heinz-Schweiker rivalry would be renewed.

This year, Heniz appeared to be moving adroitly for control of the state's delegation to the 1980 presidential convention by means of Thornburgh's gubernatorial candidacy. The former Justice Department official announced early, signed up television image-maker David Garth (who had also handled Heinz) and appeared a strong favorite to beat Specter, still carrying the scars of his battle with Heniz.

But Schweiker once again would not be outdistanced. After toying publicly with running for governor himself, he found a better ploy when the Carter administration's bungled attempts to remove Marston as the Philadelphia prosecutor turned "little David" into a Pennsylvania folk hero.

With Schweiker's encouragement and the day-to-day political advice of David Newhall, Schweiker's highly regarded political aide. Marston launched a late and lightly financed campaign.

While Thornburgh and Specter bang home their lawmen images in dozens of television spots, Marston has only the bare bones of a media campaign or an organization.

He and his wife drive, without aides, from shopping center to shopping center - enjoying countless variations on a dialogue that went like this with David Zimmerman, a sales manager they met at a shopping center near here:

"Hi, I'm Dave Marston. Running for governor."

"Oh, you're the guy that . . ."

Yeah. I'm Jimmy Carter's friend."

"Don't say that. I voted for the guy. What they did to you was really rotten. You're going to get a lot of support."

"Give me a vote and we'll take care of those politicians.

Wherever he goes, Marston finds local reporters and television stations eager to interview Pennsylvania's favorite martyr, a fact that Thornburgh in particular finds frustrating. Thornburgh stayed on at the Justice Department for the first few months of the Carter administration to provide continuity on some criminal cases, then resigned quietly. "If I had only known," he says, "I would have insisted on being fired."

Meantime, striving mightily to avoid the civil war between the senators, Bob Butera has put together the best organization in the Republican field - a network of fellow legislators and an estimated 11,000 volunteers in storefront offices. He has a home base in suburban Philadelphia's Montgomery County. Some observers think Butera could win, despite his lack of prosecutorial credentials.

Some parallels exist in the Democratic field, but without the overlay of senators' ambitions.

Flaherty is the free-spirit candidate, riding his hometown popularity in Pittsburgh and western Pennsylvania and a media campaign emphasizing his record as a mayor who reduced the public payroll and cut taxes. (His opponents say the city is still recovering from Flaherty's austerity moves.)

But Flaherty, like Marston, is unencumbered by any semblance of a statewide organization. And, like Marston, he is exploiting his difference with Jimmy Carter.

That might seem hard for a man who seldom left Carter's side during the entire Pennsylvania primary and general election campaign in 1976, and who served for a year - to mixed reviews - as No. 2 man in Carter's Justice Department.

But Flaherty - who can foresee political trends sooner than most - signed his Carter divorce when he quit the Justice Department. Now he loses no opportunity to tell how he fought - unavailingly - to keep the administration from firing Republican Marston.

Ask about his relationship now with Carter and his answer sounds very much like, "Jimmy who?"

Flaherty was the favorite for the Democratic nomination almost from the start of the race, but, in the last two weeks, some observers have begun to switch their bets to Bob Casey, the anti-Shapp former auditor from Scranton.

Casey has as much independence from the Shapp administration scandals as does Flaherty, and he has a statewide organization which Flaherty lacks, including some allies in Philadelphia, where Flaherty is almost alone.

But now a final irony intrudes. For all the attention the Pennsylvania battle has drawn from out-of-state newspapers, the citizens of the commonwealth - soured by the scandals of recent years - appear to be in a classic posture: "a plague on all your houses."

Many managers on both sides expect an exceptionally low vote, which means that the traditional power-brokers on both sides may yet control the game.

In the Democratic race, that would probably help Kline, Shapp's liberal Democratic lieutenant governor, who has the backing of the state employes, the teachers and much of organized labor. It is also rumored that he may find support from lieutenants of Philadelphia Mayor Frank Rizzo, who are most interested in having one of their own, Thomas Leonard, nominated for lieutenant governor.

On the Republican side, a somewhat comparable position is held by Specter, who is backed by Philadelphia GOP leader Billy Meehan. Meehan and Specter have established a friendly working relationship with the Republican organization of suburban Delaware County, which has its own candidate for lieutenant governor, Faith Ryan Whittlesey, against the favored William W. Scranton III, son of the last Republican governor.

The search for the most honest man in this wide field would make even old Diogenes squint.