For two years, this writer has been consumed by two subjects.

First, the presidency of Richard Nixon, in whose White House I served from its first day to its last, covered in my new book, “Nixon’s White House Wars: The Battles That Made and Broke a President and Divided America Forever.”

The second has been the astonishing campaign of Donald Trump and his first 100-plus days as president.

In many ways, the two men could not have been more different.

Trump is a showman, a performer, a real estate deal-maker, born to wealth, who revels in the material blessings his success has brought. Nixon, born to poverty, was studious, reserved, steeped in history, consumed with politics and policy, and among the most prepared men ever to assume the presidency.

Yet the “mess” Trump inherited bears striking similarities to Nixon’s world in 1969.

Both took office in a nation deeply divided.

Nixon was elected in a year marked by the assassinations of Martin Luther King Jr. and Robert Kennedy, race riots in 100 cities, and street battles between cops and radicals at the Democratic National Convention in Chicago.

Trump’s campaign and presidency have also been marked by huge and hostile demonstrations.

Both men had their elections challenged by the toxic charge that they colluded with foreign powers to influence the outcome.

Nixon took office with 525,000 troops tied down in Vietnam. Trump inherited Afghanistan, the longest war in U.S. history, and wars in Iraq, Syria, Libya and Yemen.

Nixon pledged to end the Vietnam War with honor and begin an era of negotiations — and did. Trump promised to keep us out of new Mideast wars and to reach an accommodation with Russia.

Probably no two presidents have ever faced such hostility and hatred from the media. After his 1969 “Silent Majority” speech on Vietnam was trashed, Nixon declared war, authorizing an attack on the three networks by Vice President Spiro Agnew.

Trump has not stopped bashing the media since he came down the escalator at Trump Tower to declare his candidacy.

Trump and Nixon were supported by the same loyalists — “forgotten Americans,” “Middle Americans,” “blue-collar Democrats” — and opposed and detested by the same enemy, a political-media-intellectual-cultural establishment. And this establishment is as determined to break and bring down Trump as it was to break and bring down Nixon.

Nixon’s achievements in his first term were extraordinary.

He went to Beijing and opened up Mao Zedong’s China to the world, negotiated with Moscow the greatest arms limitation agreement since the Washington Naval Treaty of 1922, and withdrew all U.S. forces from South Vietnam.

He desegregated the South, ended the draft, indexed Social Security against inflation, created the Environmental Protection Agency and the Occupational Safety and Health Administration, named four justices to the Supreme Court, presided over six moon landings, proposed a guaranteed annual income, took America off the gold standard, and let the dollar float.

He then won a 49-state landslide in 1972, creating a “New Majority,” and setting the stage for Republican control of the presidency for 16 of the next 20 years.

But in June 1972, a bungled bugging at the DNC, which Nixon briefly sought to contain and then discussed as the White House tapes were rolling, gave his enemies the sword they needed to run him through.

The same deep state enemies await a similar opening to do to Trump what they did to Nixon. Rely upon it.