I can't speak to programmers, but I can speak to the quality of government economists and some other scientists.
Generally, industry bids away the best talent with much higher salaries. That doesn't mean there aren't good researchers who work for the government, but they aren't elite.
They also tend to be behind the times. Because government jobs are so secure, there's less incentive to keep up with new developments. These jobs also attract people who value job security over production.
I agree that safe jobs attract sub-par employees. Yet, somehow the NSA and CIA have very impressive capabilities. It's possible that the employment logistics are different and they hire contractors (Edward Snowden was a contractor, for example), or maybe they let elite hackers off the hook in criminal cases in return for a few years of service, etc, but however they do it, they clearly have access to top talent.
reply
Most likely what's going on is a combination of outside help (contractors and collaborator tech companies) and hiring in established specialists to develop specific capacities. They will make competitive offers for specialized positions of "need". The rest is likely just careerists implementing well known processes with access to enormous computing resources.
Also, wrt the NSA, they do gobble up many of the top math PhD's, so that would explain their cryptography abilities. There's generally not a lot of industry demand for math phd's.
reply