Many Pies

Many Pies

Wednesday, December 18, 2013

Bitcoin - digging deeper and deeper into what it's all about

At the moment I'm finding Bitcoin really interesting.As you can tell from the post about Cryptography for Curious Kids I'm interested in cryptography. I've read overviews and that Wikipedia article I've linked to, and the Bitcoin wiki. I find that I grasp the overall concept. Then I read into the detail and think I've grasped it at a deeper level. Then I go away and forget about the detail and have more questions which means I need to read again, and deeper. Almost every fact seems to raise more questions. It's almost like an adventure game:

Bitcoin is a peer to peer digital currency. Where do you want to go?
N: How do they get created?
E: Can you have a physical Bitcoin?
S: What does it mean to have a quantity of them?
W: How do you exchange them for other currencies?

>S
You have chosen S. The way that you have a Bitcoin is that everyone taking part in Bitcoin has a record of all the transactions that have taken place since they started being used, so everyone agrees that you have a certain number in your wallet.(OK not everyone taking part, but a lot of people.)

N: What is a wallet?
E: How does this information get synced between everyone?
S: What's to stop people falsifying the information?
W: How can you have fractional parts of a Bitcoin?

And so it goes on: mining, pooling, the blockchain, public/private keys, speculation about deflation, bubbles, anonymity, hashes, really big numbers.What's not to like?

Articles by my favourite bloggers (linking doesn't mean I agree)
I sold some Bitcoins by Tim Bray
Why I want Bitcoin to die in a fire by Charlie Stross

Tuesday, December 10, 2013

Publishing computer games

I was looking up in the loft for the paperwork I kept from when I was a teenager and sent in games for the ZX80, ZX81 and Spectrum to magazines. I didn't find that, but I found some other paperwork:
ZX81 ROM disassembly

A friend on Facebook found a copy of the Sinclair User Annual 1983 which had one of them in.


(Update: I called this game "Beancup" but I've just found out (Nov 2016) it's called Oware amongst other names.) I didn't always buy the magazines that published my games, because that would eat into the money I'd made, so it was quite exciting to see my work from so many years ago revived again. I didn't have a printer, so unlike many of the other listings this one was typeset.

Some things strike me about this:

  • no function names, you just GOSUB a line number
  • line numbers!
  • I'm surprised how compact it is - a two player game, plus the computer's strategy in just a few lines
Update: I was searching my blog archives for the word Sinclair and I came across this post about mobiles and gaming. What is interesting is the article I link to which talks about the potential for mobile (what we now call) apps. This was pre iPhone and Android app stores, so presents a "historical" perspective before things all changed.

Update (14 April 2023): while visiting my parents I found the original game which inspired me to write the program. 



Tuesday, November 26, 2013

New office - furniture and rolling display


There's a good post with lots of pictures of our new office on the Wycliffe Centre move blog. I've been involved in the office layout planning since near the start of the process and one of the things we needed to consider was which office furniture to get. Because our previous furniture was from all sort of different sources it was very mismatched, so we wanted to spend money on getting new desks. (We managed to reuse a number of other bits of furniture, such as non-desk chairs, bookcases and some cabinets.) In the end we went with furniture company called Ofquest. Even with a generous discount it wasn't cheap. What we got for our money though was solid construction, a degree of reconfigurability, and really useful features, like a cable tray under the desk and clip on cable guides for the legs. It should last us a number of years, and survive another office move should we move before it wears out.

One of things of lesser importance that I've worked on with Ruth, our content person, and Stuart and Andy, my IT colleagues, is the TV display you can see above. Stuart and Andy got a Raspberry Pi going booting into the Chrome browser and displaying a page from our intranet. The page changes every few seconds and as well as showing prayer items shows things to praise God for, internal notices, the picture of the week from wycliffe.net. For that page, and another one which screenscraped our own wycliffe.org.uk site I used a bit of  XPath, obtained via Chrome's web inspectory thingy, which makes it very easy to get at HTML content. Here's a fragment of the code I used:

$pageHTML = file_get_contents($url);
if ($pageHTML) {
$dom = new DomDocument();

$dom->loadHTML($pageHTML);
$xpath = new DOMXPath($dom);
$entries = $xpath->query('//*[@id="image"]/img');

if ($entries) {
$tag1HTML = nodeContent($entries->item(0), true);
}
}

The user-editable pages were done with Perch, a very neat content management system. It's not suitable for large sites, probably defined by complexity of navigation rather than number of pages. It's very quick to get going on though. I used the API to write a custom app which removed items from a page when an associated expiry date had passed. As you've got access to the source code as well as the API documentation I was able to write something which delved into the Perch innards without too much effort, once I understood factory classes. When I needed support I got a quick response (_/- confusion - doh!).

Monday, October 28, 2013

Cryptography for curious kids



Here's part of a book I may never write.

Introduction

Why kids?

I read books on codes and ciphers when I was a kid and I loved them. Now I'm grown up I still like reading about codes and cryptography (and maths and science). I don't understand everything, but I reckon I can explain enough so that kids can have the same rough understanding of what's going on as me. There are still books on codes and ciphers for kids, but they don't go deep enough (note to self: check whether this is actually true before embarking on book). When I was a kid I wasn't aware that codes played that much part in life, apart from whatever spies got up to. These days however as soon as you go to a website and a padlock appears in your browser then you're using cryptography. This book still may not go deep enough for you, but hopefully it will take you deep enough to either satisfy your curiosity. You don't have to be a kid to read it, but the alliteration of the ks and cs sounds good.

Why curious?

You don't have to know how things work in order to use them, but if you're the sort of person who wonders what's really going on then this book is for you.


A shark through a drainpipe - one way hashes

Sharks have quite prominent gills. I can imagine, (though I haven't actually done it myself), that if you put a shark down a drainpipe that was just about wide enough to take it, it would be quite hard to drag it back up the other way. Not impossible, but so hard that you wouldn't really want to bother. A one way hash is like that.

Imagine you have a really long brioche roll with chocolate chips spread along it. They are spread so that every centimetre of roll either has one or no chocolate chips in it. You could chop this roll into 32cm pieces and then compare one pair of pieces side by side like this.


You then look at each centimetre of the rolls and follow the following rules:
If one of the rolls has a chocolate chip at that point then you transfer that chip to a new roll at the same point.
If neither of the rolls has a chocolate chip then the new roll doesn't get one either.
If both have a chip then the new roll doesn't get one.

This set of rules is called the XOR function (exclusive or - one or the other but not both). 

You then compare another 32cm length with the new roll until you've used up all the roll. (If the last bit is less than 32cm long then assume that it's actually 32cm long with no chips in the bits that aren't there.) At the end of it you'll have a brioche roll with a pattern of chocolate chips and gaps. As there's no randomness if you start with a certain pattern in your original roll then you'll always end up with the same pattern in the final roll. A set of rules used in this way is called a hash function. In practise hash functions are more complicated.

This is a one way hash. There could be two different original patterns that end up with the same final pattern. However to try and work backwards from the final roll to work out the original roll is hard - like dragging the shark backwards through the drainpipe. So it's not exactly one way, but near enough.

You could come up with different rules of chopping and combining and a good hash function will mean that if you start out with two original rolls that only have one chocolate chip difference the final roll will be really different.

So what's the use of a hash function? One thing you can do with it is to check that a file that you've downloaded is complete and hasn't got corrupted on the way. If the site you download the file tells you the hash of the file then you can use a program to work the hash of your file and if it matches then it is very probably the same as the original. Like the two rolls that are only different by one chocolate chip, a small corruption would give you a different hash, so it's really unlikely that the file would be corrupted in such as way that it's different to the original, but has the same hash.

Hashes and cryptography

One way that hashes are used in cryptography is when checking passwords. If a computer had a list of usernames and passwords in a file somewhere, and someone got that file, then they could log in as any one of those users. So the passwords are stored in hashed form. When someone types in their password it's hashed in the same way and then checked against the stored password. This is where the "really hard to find another thing that when hashed gives the same result" property is important. 




Thursday, October 24, 2013

Blue Pi Thinking from the University of York

I did Maths and Computer Science at the University of York (they don't like people calling it York University) and this year they gave new Comp Sci undergrads a Raspberry Pi before they started the course. I'm pondering what I would have done had that been me.

Wednesday, October 23, 2013

A time of "lasts"

High doors
So we're moving offices and Tim has written a good post Goodbye Wycliffe Centre. I've just been on what might be the last time I walk around the outside of our grounds. Yesterday we had the last of our weekly "Tuesday fellowship" meetings. (In future we'll meet monthly.) It's a time of lasts.

Update: in fact I took two more walks.

Tuesday, October 15, 2013

My heroine for Ada Lovelace Day - Kathy Sierra


My heroine for Ada Lovelace Day this year is the "programming instructor and game developer" Kathy Sierra. I've written about her return to blogging previously, but the thing that made me admire her even more was reading parts of one of the Head First books that she co-authored recently. It really focussed on making sure that the knowledge and wisdom got from the authors' heads into your own. I'd seen her thinking in the Creating Passionate Users blog, but here was the thoughts applied to a particular topic, Design Patterns in the case of that particular book and I was very impressed. You can find her on Twitter as @seriouspony.

(Picture by Ed Schipul. Licensed under a Creative Commons Attribution-Share Alike 2.0 Generic license.)