The Cuban government has formally opened the door for a mass exodus to the United States of all Cubans who want to leave here, a number that officials have suggested could reach hundreds of thousands.

The sudden Cuban offer, contained in a cryptic announcement published in Tuesday's edition of the official newspaper Granma, is expected to affect far more than the 10,000 persons who originally took refuge in the Peruvian Embassy here two weeks ago.

Top Cuban Officials privately indicated the anticipated flow of refugees may top the massive flights of 1959 through 1961 and 1965 to 1966, when several hundred thousand opponents of Cuba's communist government fled the country.

The news that anyone who could get a boat from the United States to pick him up could leave spread like fire through Havana. A line of people more than two blocks long formed today outside the downtown telephone company building. There were waits of up to 24 hours for calls presumably to friends and relatives in the United States.

Three days ago, the first boats arrived from Florida at the small port village of Mariel, 15 miles west of here, in a private effort by U.S. Cuban exiles to pick up the Peruvian Embassy refugees. Those who take advantage of the new exit offer are expected to leave in the same way.

The Granma announcement said the "rhythm" of departures from Mariel had been going well. It said some of the arriving exiles had asked permission to take Cuban relatives along with the embassy refugees. The requests, Granma said, had been "courteously received" and "fully complied with."

Then, in a cryptic phrase, the article concluded: "In two words, we have withdrawn protection from the Florida peninsula."

This phrase, which has caused alarm among U.S. diplomats here and wide commotion among Cubans, was considered a clarion call. It is exactly the same message the government sent two weeks ago, when it said it had "withdrawn police protection" from the Peruvian Embassy. Aspiring refugees read it correctly as the green light to run for the embassy to receive emigration papers, and within 48 hours more than 10,000 Cubans had jumped the gates.

"It is that same language, and it is intended to be," said a key diplomat here. "There is no question that it means anyone who can arrange to be picked up can go to Florida."

Although Cubans have tried to make free-lance escapes in the past, and last year about 400 persons, most of them hijacking boats, arrived in Miami, Cuba until now has regarded such undocumented departures as illegal. When caught, Cubans can be sentenced to up to three years in prison.

The indirect announcement appeared to take U.S. officials here by surprise. But there were indications more than a month ago, even before the Peruvian Embassy crisis began April 4, that President Fidel Castro was considering such a plan, and setting the stage to hold the U.S. responsible.

On March 8, in a speech to the Cuban Women's Federation, Castro chronicled recent U.S. offenses against Cuba, including, the encouragement of "illegal departures" by boat.

"We trust they will take measures to discourage illegal departures from the country," Castro said. "Otherwise we would also have to take measures."

The obvious reference was to 1965, when Castro offered to let all would-be emirgrants leave from the port of Camarioca, an offer that eventually resulted in thousands of departures by private boats, U.S. charter ships and finally an airlift.

"We have warned [the United States]," Castro said in the March 8 speech. Mentioning Camarioca, he said he hoped Cuba "won't be forced to take such measures again."

No one knows exactly what the rules will be this time. Granma spoke of the departure of Cubans who have relatives in the United States and of the Peruvian Embassy refugees, but Cuban officials said the departure was "negotiable" for others as well.

At least six boats filled with Cubans arrived in Key West, Fla., today and hundreds more were reported to have begun the 180-mile round trip.

Hildo Romeo, a representative of the Miami Cuba exile community, who is coordinating the arrival and departure of Miami-based boats here, told reporters that if the first trips this week were successful, he anticipated hundreds of others shortly.

The exodus, so openly encouraged by the Cuban leadership, comes at a time that is officially described as "difficult" for the Cuban economy.

Cuba, which produces few consumer goods, has been hard-hit by international inflation despite the massive financial assistance it receives from the Soviet Bloc. The sugar and tobacco crops, the mainstays of Cuba's export earnings, have been seriously damaged by blights.

Fidel Castro and his brother, Raul, the defense minister, have harped in recent months on mismanagement, apathy and corruption in most of the state-run sectors of the economy. Unemployment has increased sharply and Cubans have been told there is no end in sight for economic austerity and rationing.

The economic pressure and growing political and material discontent apprently contributed, along with a willingness to reunite separated families, to last years' decision to make it easier for Cubans to leave the island.

But ironically, as the government eased up on the travel ban, it found that many more people were getting exit visas than there were opportunities to leave. No figures could be obtained, but the pressure-cooker effect helped lead to scenes like those at the Peruvian Embassy, officials here believe.

"Systematic, normal legal departure is very difficult for Cubans," a top government official said in an interview today.

While most Cubans wanting to leave insist on going to the United States, the U.S. quota is much smaller than the demand for visas. Besides the United States, only Spain has received small numbers of Cubans in the past year. Until now, "Europe and Latin America refused to take any Cubans at all," the official said.

Last year the U.S. Embassy gave visas to almost 10,000 people. The majority were 2,800 former prisoners and their families. A new program for former prisoners now aims at processing 1,000 people each month until October, U.S. sources said.

Altogether, 800,000 Cubans, out of a population of 10 million, have fled to the United States since Castro's guerrillas launched their socialist revolution in 1958, and Havana is alive with talk of a new "Camarioca" this week.

"Of course, the exodus speaks badly of the Cuban communist system," said a prominent European diplomat here, "but in the communist world it stands out positively. You could look at this as a rather humanitarian, non-violent, non-Stalinist type of purge."