The firing of the head of the National Security Agency was only the latest move that has eroded the country’s fortifications against cyberattacks, especially those targeting elections.