Depressed over his failing marriage and looking for money he thought might help fix it, John Anthony Walker Jr. made an "impulsive decision" to spy for the Soviet Union, he testified here today.

"I was depressed and I committed a desperate act," Walker said in his first public description of his 18 years of espionage. "I contacted the Soviet Union and agreed to sell secrets to them."

Walker's testimony comes in the fifth week of the trial of his friend and former Navy colleague, Jerry Alfred Whitworth, the last of four men accused in the Walker espionage ring to face trial.

Walker's testimony provided the most direct and graphic evidence linking Whitworth, a retired Navy communications specialist, with the espionage ring that Walker masterminded and that authorities have described as the most damaging in decades.

Smiling nervously at times and fiddling with a pencil as he testified, Walker detailed his espionage activities from their start in early 1968, when he "simply walked in the front door" of the Soviet Embassy in Northwest Washington and offered to sell information about codes, the most sensitive of military secrets.

Walker's testimony, which is to continue Tuesday, included a description of how he allegedly recruited Whitworth -- a man who he believed had "larceny in his heart" -- to become his partner in the espionage operation.

Whitworth, 46, the man Walker described as his "best friend," sat impassively as he listened to Walker describe the spy operation in matter-of-fact language that sounded more like running a business than passing military secrets.

Walker, 48, who pleaded guilty to espionage in federal court in Baltimore Oct. 28 and faces life in prison, promised to testify against Whitworth in return for a reduced sentence of 25 years for his son, Navy Seaman Michael Lance Walker. The younger Walker, 22, also pleaded guilty. John Walker's brother, retired Navy Lt. Cmdr. Arthur James Walker, 51, was convicted of espionage last August and is serving a life term.

Under questioning by Assistant U.S. Attorney William S. Farmer, John Walker said today that in early 1968, when he was a communications watch officer at the Atlantic submarine fleet headquarters in Norfolk, he decided to try to make money selling cryptographic "keying material," or codes.

He decided to offer the material to the Soviets, Walker said, because "I perceived them to be the principal buyer in that market." Walker said he took a "keylist," or code, for the KL-47 code machine, drove to the Soviet Embassy, and told a somewhat "shocked" employe outside that he wanted to see the security officer.

"I showed him the keylist and told him I was interested in dealing," Walker said.

Walker said the Soviets asked him to provide them with a "shopping list" of material that he could pass them.

"I told them exactly what I had access to -- which was everything," he said.

Walker said the Soviets gave him a miniature Minox camera to photograph documents and a tiny device to figure out the complicated wiring in military coding machines.

Over the objection of defense lawyer James Larson, Walker showed the jury the "rotor decryption device," about the size of two credit cards hinged together.

From 1968 until his arrest on May 20, 1985, Walker said, he made about 30 "drops" of classified information at various points in suburban Washington.

Walker said he decided to expand the spy ring when he realized it would be difficult for him to pass the Soviets information while he was serving aboard ships and because he hoped to retire from the Navy after serving 20 years. He joined the service in 1955.

Walker met Whitworth in 1970, when Walker was director of a Navy communications school in San Diego where Whitworth was teaching. The men became close friends, spending nearly every weekend sailing on Walker's boat, "The Dirty Old Man." Walker "began to contemplate him [Whitworth] as a potential recruit to help me in the spying business," Walker testified, and he started asking his friend questions to "probe possible larceny in his heart."

On one occasion, Walker testified, the two were discussing the movie "Easy Rider" and "Jerry said he wished it were possible to make a one-time score . . . [and discussed] what he would do with the money.

"I decided at that point," Walker continued, "that Jerry Whitworth would be an adequate recruit."

A few years later, in September 1974, Walker said, he popped the questions directly.

Over drinks at Boom Trenchard's Flare Path, a restaurant at the San Diego airport, Walker said, "I made the sales pitch."

Walker told his friend he was "interested in using him in an illegal act," and Walker had Whitworth "swear a blood oath" not to turn Walker in if Whitworth was not interested in participating.

Whitworth, he said, "was excited and was interested in hearing what I had to say."

Walker testified that he then disclosed that he was selling classified information and told Whitworth that "I could build him into the sale."

When Whitworth asked about the recipient of the information, Walker said, Walker told his friend he was not certain. He said the buyers were "possibly organized crime, the Mafia, allied countries such as Israel or private organizations such as the publisher of Jane's Fighting Ships."

Prosecutors have said in court papers that Whitworth eventually became aware that the material was going to the Soviets.

Walker said he told Whitworth he could earn about $2,000 monthly for "standard message traffic at the secret level," and more for coding information.

He said Whitworth expressed reservations about the risk of engaging in what both men "knew . . . was the most serious crime," Walker said.

The "major selling point," Walker said, was that he had been operating for more than six years without being detected.

"The chances of getting caught were about nil," Walker testified. "Since I had not gotten caught for a number of years, there was no reason why we should ever get caught."

Walker's former wife and his daughter tipped off the FBI to the operation belatedly -- in November 1984.

Before Walker started testifying, U.S. District Judge John P. Vukasin Jr. ruled that prosecutors may introduce results from a polygraph test this month allegedly indicating that Walker was being truthful when he told the FBI that Whitworth gave him classified information in exchange for money. Vukasin affirmed his ruling permitting defense lawyers to introduce results of another polygraph test. That test, administered to Walker last July, before his guilty plea, indicated that he had been deceptive in some of his statements to the FBI, according to the government.

Whitworth is charged with 13 counts of espionage and tax violations.