The philosopher Jeremy Bentham called it the Panopticon. It was his notion of the ideal prison in which every inmate would be exposed to 24/7 surveillance. What he could never have known in the 18th century was that an entire society could become a panopticon

But that is what is happening. The technology of surveillance by police and security agencies, as well as private technology companies, is so powerful and sophisticated that our archaic judicial system cannot keep abreast of developments.

The latest revelation in the surveillance state, as revealed by Paul Hutcheon in the Sunday Herald, is that Police Scotland has been spying on digital data to try to try to find out details about journalists' contacts. This is probably illegal, though it comes as little surprise.

Under the Regulation of Investigatory Powers Act, 2000, the police already have wide powers to snoop on our internet trails. These powers are to be vastly extended by the UK Government's forthcoming Investigatory Powers Act. This "snoopers' charter" will require phone and internet companies to retain mobile phone traffic and email traffic for at least a year.

This looks like an attempt to legitimise what has already been happening. As we learned from the whistle-blower Ed Snowden, the monitoring service GCHQ is already in the business of bulk collection and storage of internet traffic under secret protocols such as Tempora and Prism.

Now that nearly all of society is online, or about to go online, there really is no hiding place. Every desktop computer in every police station is being hooked up to a vast network of digital scrutiny.

Police Scotland is in the process of upgrading the network of digital CCTV cameras across the country and hooking output to a new computer system, i6. Soon every officer will carry a camera on his or her shoulder.

This will increase the potential for casual and irregular surveillance by inquisitive cops. A recent example was the spy-in-the-sky close-up picture of the comedian Michael McIntyre that was taken by a police helicopter and tweeted by officers for laughs on the internet.

But this is no joke. The technology of telephone tapping and email monitoring has been transformed in little more than a decade. You can see the difference by comparing the 2004 US crime drama The Wire and this year's BBC offering, The Interceptor, inspired by revelations from former HM Customs undercover officer and eavesdropper Cameron Addicott.

The Wire concentrated on the difficulties of monitoring drug dealers in Baltimore where, to legally tap a phone, the police had to go through a complex procedure of judicial monitoring. They even had to have the target in visual sight, from the rooftops, before they could legally listen in to the wire-tap.

In the Interceptor, detectives are able to tap into mobile conversations at the click of a mouse. Since The Wire, overlapping agencies have constructed an architecture of surveillance vastly superior to anything any fiction writer could have imagined.

The panopticon is becoming ever more intrusive. That iPhone in your pocket routinely records where you have been and whom you've been seeing. This amounts to a form of electronic tagging.

Well, if we've nothing to hide we've nothing to worry about, have we? Unless you happen to be a journalist investigating something that Police Scotland doesn't want exposed, it appears. We are handing too much power to the force.

The Scottish Government seems to believe that, because data regulation is a UK responsibility, it can wash its hands. But policing is a devolved responsibility and it is the Scottish Government that created the monster force that threatens civil liberty.

It's hardly surprising that some journalists are returning to paper and pad and holding face-to-face meetings with contacts rather than using the phone or email. We are enmeshed in as intrusive a web of surveillance as one of Jeremy Bentham's inmates.

Now, the ancient right of habeas corpus held that citizens should not be held without charge. We need a new habeas corpus for the digital age to prevent the state seizing and holding the vast body of information routinely retained on all of us.

After a reasonable interval, if they find nothing, we need to be told, as of right, who investigated us and why. The computer industry has algorithms that can ensure that, when PC Plod starts nosing into our affairs, a trace is recorded and sent to an independent regulator.

We need to shine a light back into the security state. The panopticon needs to be reversed so that every citizen has the power to look the snoopers right in the eye.