Clever and totally pointless – my first publication

Way back in the early 90s, I subscribed to a magazine (think of it like a big website but printed on paper and sent through the post) called ‘PC Plus’. It included a section called “Wilf’s Programmers Workshop” where every month, Mr Wilf Hey would present a project (usually written in GW-Basic) and discuss the principles at work. It was here where I first managed to get something clever into print, except I didn’t do it quite right.

There would usually be a brief digression at the end of his section, and in one issue, he discussed the idea of a “quine”, a program whose only function is to generate its own source code.

printf(f,34,f,34,10);

It was from this I had an idea of a creative way to produce a quine of my own. I just had to be liberal about the definition of a programming language. Here’s my (faulty) recollection of Mr Hey’s write-up of my entry…

We had a clever entry to our discussion of self-replicating programs from Bill Godfrey who sent in a floppy disk, and it meets the rules of the game.

Run the program SELFREP.EXE and it produces the “source”, PKZIP.EXE itself. He supplies a batch file which recompiles the program. First, PKZIP “compiles” SELFREP.OBJ (instead of .ZIP) and then the “linker” ZIP2EXE is invoked to produce the completed executable program.

Unfortunately, because Mr Godfrey didn’t write PKZIP, he’s technically disqualified from this contest.

Once the initial excitement of appearing in print wore off, I was kicking myself for not thinking my idea through. I only used PKZIP.EXE as the source file because I needed a file to be the source code, and PKZIP itself seemed the most applicable for that role. That decision alone disqualified me.

What I should have done is supply some “source code” such as…
   /* A self replicating program by Bill Godfrey. */
   Go();

The batch file should have just compiled (zipped) that two line text file and then linked (zip2exe) it. Running the generated EXE would have produced the same two line text file back. It would have totally complied with the rules and I would not have been disqualified! Grrrr…

I’ve long since lost that edition of PC Plus. If anyone reading this has a copy, I’d love a scan of that page please.

Picture credits
“Reading a magazine” by flickr user “ZaCky ॐ”.
“Danger – Self Replicating Device!” by Sam Ley, aka flickr user “phidauex”.

‘First Past the Post’ isn’t.

I’m a bit of a nerd for vote counting systems. So I discovered with delight that in the UK, there will soon be a referendum on changing the way votes are counted. As I write this, most of the UK (and the USA) uses a method we call “First past the post”.

It’s called “First past the post”, but it isn’t. The name is about as ridiculous as calling North Korea;  “The Democratic People’s Republic of Korea”. The country is on the Korean peninsula, so at least that name is a little bit honest.

Put what you know to one side and think about what a vote counting system called “first past the post” should look like by the name alone. It’s a clear analogy to running in a race with a “post” at the end of the track. So there’s a predetermined number of votes and the first candidate to get past that threshold wins?

Nope. “First past the post” doesn’t work that way at all.

Imagine a vote of 100 voters selecting one of three candidates; A, B and C.

A 45 votes
B 30 votes
C 25 votes

If we put the “post” at 51 votes (a simple majority), then all three candidates lost. They all fell over and dropped out of the race before anyone reached the finish. Three pathetic failures. Rather than declaring no-one the winner, the people organising the race then dig up the post and re-plant it just behind A, as if the post was always there. He is declared the first one to pass the post.

If that wasn’t confusing enough, the other counting system to be offered in the referendum, “Alternative Vote” or “AV”, does indeed look like how you’d imagine “first past the post” to work. To continue the analogy with AV, candidate C drops out of the race after the first round. The second preferences of C’s voters are counted and added to A’s and B’s total.

A 45 + 3 votes 48 votes
B 30 + 22 votes 52 votes
C 25 votes

Hurrah! After two rounds, B was the first candidate past the post. A had an early lead but couldn’t keep up as far as the finishing line, overtaken by B in the closing straight.

So remember, the vote counting system that works in a “first past the post” manner is the one called “Alternative Vote”. The one without anything like a “post” is called “First past the post”. Clear?

Picture credits:
Vote Goat by Jeremy Richardson (Mr Jaded on flickr).
Racing demons by Simon Webster (shaggy359 on flickr).

Google snooping WiFi? Don’t panic! Don’t panic!

Google have got into a bit of hot water when it emerged that while their cars drove around taking pictures for their Street View service, they collected and stored people’s private WiFi traffic. People have understandably got angry with Google for doing this, but I think some demystification is in order.


Did they collect my private data?

If your WiFi access point uses WPA with a good pass-key, don’t worry. Your network traffic is encrypted and is just noise without that pass-key.

If your WiFi is “open”, then anyone within range can collect and look at your network traffic. I would be more worried about that creepy guy in the van parked around the corner, maliciously snooping on you, spamming and browsing dodgy websites. Worrying about Google would be way down my list. Take this opportunity to switch on WPA on your access point. This article will still be here afterwards.


How come their camera cars collect WiFi data at all?

It can be used to supplement or replace GPS. Google are in the mapping and navigation business, and knowing where you are is essential to helping you get where you are going.

If you go out to some random spot in a built-up area and switch on your laptop’s WiFi gizmo, you’ll find several access points, both public and private, all with a variety of weird names. Make a list of those access points and their signal strength, compare it against a list of known access-points and their previously monitored location, do a few calculations and you’ll have your location.

No need for GPS electronics, just use the same WiFi electronics your laptop will have anyway.

That’s very nice, but even my WiFi address is private. They shouldn’t have collected even that.

Is it? By necessity, your WiFi access point has to broadcast it’s identity to the public in the clear. Your neighbours might be using WiFi too, possibly within range of your own laptop. When it hears something broadcast, it loads the packet and looks to see if its from an access point it knows about. It’ll be receiving lots of noise from your neighbours and silently throwing away anything it’s not interested in.

Now apply the principle that no-one else should even look at a packet’s identity. You’ll have no way of knowing which packets are yours and which are someone else’s unless you do look at the access points identity. It’s part of the protocol.

But they collected private traffic as well as just the access point’s identity. How could that be accidental?

Even when you are only interested in the identity of an access point, you need to collect a whole packet before it’s useful. The trouble is that radio on it’s own is subject to noise and interference. To fix this, the clever people that designed the WiFi protocols added a noise check. Before a packet is broadcast, some simple calculations are done on the content of the packet and the result is added on the end. The recipient takes the packet and performs the same calculation on the content. If the result the recipient ends up with is the same as the number on the end of the packet received, it can be reasonably sure the packet arrived without errors.

For this to work, the recipient needs the whole packet. If they only listened to first bit where the sender’s identity is stored, there is a risk of noise creeping in, masquerading as correct data.

But why did they store the whole packet after the error check has passed?

Very little of a software developer’s work is making things from scratch. Instead, we reuse and build upon work done in the past. We make reusable components that can be reused for different things.

I can only speculate here, but I imagine that when Google put this project together, they would have taken a generic WiFi receiver component which has been well tested and trusted rather than build an entirely new one. The packet is the natural unit of a WiFi receiver, so it would be expected that generic components designed to deal with WiFi traffic would store whole packets as a matter of routine.

Wouldn’t they have noticed a huge data file if they were only planning to store a fraction of what they did collect?

They would have been taking pictures and collecting many image files at the same time, so the space taken up by captured WiFi traffic would be a small proportion. Even if they were only collecting WiFi locations, the amount of storage that would be required in the field isn’t quite so predictable. Databases aren’t simple files where one item is stored one after the other, but are complex structures with indexing and redundant copies.

I imagine that if I were an engineer at Google and I wanted an estimate of how many hard disks to buy, I would send the car out on a short test journey and see how big the database is when it came back. Multiply that figure by however far the car will be going and that’s how much storage I’ll need. Hard disks are not that expensive these days, so spending engineer’s time working on reducing the amount of storage needed might not be a good economy.

Even so, collecting private network traffic is illegal. If I were caught eavesdropping, I probably wouldn’t get away with it.

(I’m not a lawyer, and this is not legal advice. If you take legal advice from a software engineer, you’re insane.)

If Google were taken to a criminal court over this, they could show that there was no intention to eavesdrop as I’ve outlined. If they take steps to securely destroy the additional collected data, no-one has been harmed here. Prosecuting this “crime” would be a petty reaction to a simple oversight.

But I don’t trust Google to not look at and abuse the collected private data.

If you’re not using WPA, your private data has been broadcast to all and sundry in range since you started using it, and you’re only worried now?

Picture credit: ‘Shot of Daventry area while cycling’ by… me!

Paying for Power

Being an evil genius, I’m obsessed with getting as much power as possible. If only I could get power for nothing, but alas, I have to pay for it.

In England, and most of the western world, we have a well established system of sending electricity from the power stations to me and sending money in the opposite direction. It works, but I think we can improve on it.

An Electron’s Journey

Electricity starts life at the power stations. They sell their power supply on the grid at market rates, competing with other power stations. The price of electricity fluctuates over the day. If the price goes down far enough, they might switch off the generators, keeping their raw materials for when the price goes up. A wind farm can’t keep stocks of wind in reserve, so they will stay online all the time regardless of the price.

We, the public, never see those fluctuations in price. Instead, we purchase electricity from a supplier who deal with the power stations. The suppliers usually charge us a fixed amount per unit of energy, sometimes having a daytime rate and an overnight rate, but the price they charge us is fairly stable, only changing the rates every few months.

(As well as the suppliers, we also pay the companies that maintain the grid system and meters in our homes. This article is not about them.)

When all is said and done, what do the suppliers actually do? They don’t generate the electricity and they don’t bring it to us. They are middle-men who flatten out the price, charging a bit more than the expected average price, like an insurance premium, to compensate for the risk of over-demand and price rises. Do we need that service? We have insurance to spread the risk of unexpected events, not for the everyday costs of life.

What if, instead, we had a minimal supplier that just handles the accountancy at a low cost, quoting a price that changes every five minutes, tracking the wholesale price. (Perhaps having an easy to use gizmo that displays the current price.) With this type of supplier, we would probably save money over the long term. After all, we wouldn’t be paying that insurance premium any more.

But more important than that, it would give us an interest in when we use electricity. At the moment, we really don’t care that the price of electricity rises dramatically during the adverts on popular TV shows. We all switch on our kettles at the same time, not really caring about the economics. If we felt the rise in price, we might plan our tea making better to avoid these peaks and save some money.

This plan wouldn’t have worked when the grid was originally built, but computer and communications technology have advanced to point where we can finally think about pulling down the old ways of working. I’m looking forward to it.

Picture credits.
Nuclear power by koert michiels on flickr.
insurance prohibits ladders by stallio on flickr.

The Making of an Evil Genius

When I was around 9 or 10 years old, my school, as they would every year, put on a Christmas show. The younger children would re-enact the birth of Jesus of Nazareth and then the older children would perform a play. That year, we were performing Grimm’s Snow White.

I wasn’t performing on stage though. Instead, I was in charge of the music. We had a cassette of all the music and the children on stage would sing along. I would press play when its time to sing and after, position the cassette for the next song.

I wouldn’t know it at the time, but it would be this rather mundane task that taught me one of the most important lessons of my life.

A “technical hitch”

The music cassette had all the tunes with large gaps between each song. The cassette player was an early 1980s era device with a mechanical counter and a button to move all the dials back to zero. The number on the counter weren’t anything useful like seconds but how many times the motor had turned, or something like that. Fortunately for me, the teacher organising the play had gone to the trouble of writing down the counter position for each song and the order in which they are to be performed. What could go wrong?

Indeed, what could go wrong? A few days or so before the big performance,  we did a dress rehearsal and I demonstrated I could operate a cassette player without assistance. Everyone was happy.

Finally came the day of the show. Before the audience had arrived, the teacher told me to position the cassette for the first song and I did that exactly. Everything was ready. During the show, the first tune was played without a hitch and after the song was over, I dutifully positioned the cassette for the next song.

Time for the second song… disaster!

I had pressed play but instead of music, silence. I could hear the children on stage singing “We dig-dig-dig-dig-dig-dig-dig in a mine…” until they realised there was no music. The teacher duck her head behind the curtain and asked what was happening. I showed her the tape was running and I didn’t know what was wrong. She had to go up on stage and apologise for the “technical hitch”, to much laughter from the audience.

Truth is, I knew exactly what went wrong and I was already fixing it. What happened, was that when the younger children did their nativity play, their teacher was using the same cassette player for their music. When they finished, they put our cassette back in the player but the counter was all messed up. My first song was fine because the tape was already in place, but when I positioned the cassette for the second song, it was based on a counter that was in the wrong place. I had been playing one of the gaps between songs.

What’s more, I remember thinking that exactly this would happen while watching the earlier nativity play. I was sitting there thinking “I hope they put tape counter back when they finish.” But I said nothing, after all, the teachers were in control and they would have thought of this too and wouldn’t want me bothering them. I mean, they’re adults!

While I was rather mocked by the other children for spoiling an otherwise perfect performance, it turned out to be one of the most important moments of my childhood. It taught me possibly the most valuable lesson I’ve ever had.

People in authority can be wrong.

After that incident, I started looking at adults in a new light. Not just teachers, but my parents, politicians, bishops, experts, celebrities, anyone in authority. I finally saw them as the human beings we all are.

Picture credits:
“Samantha’s Christmas nativity play” by alecea on flickr.
“Soundesign tape deck” by kumar303 on flickr.
“Silence */” by circo de invierno on flickr.