The Haunted House

Tuesday, October 02, 2007

A Blast From The Past Part 2



A few weeks ago I wrote about a little blast from the past with a game I worked on at Argonaut Software called Croc, on the Color Gameboy. But today I found another blast from the past that goes back even further than the year 2000. Back when I where a lad, and at school, I worked with my friend Chris Rundell on a game called Dark Mission for the Amiga. We were lucky enough to get a publishing deal and I remember going down to Bath to visit Future Publishing where I was interviewed about the game, which was called Dark Mission. This interview and game preview was printed in the March 1994 edition of Amiga Power.

I still have a copy of the magazine as Amanda managed to find a collector in Florida who sold her a copy of the magazine before we got married as I had lost my old copy. But it was quite cool to find this website which has every page of the scanned. You can view a full page version of the interview here, or click on the image below.



The game was an isometric action adventure. You play a marine sent to a remote colony to rescue it's inhabitants and rid the planet of the evil Vetoquel scum. Yes yes, I know. It sounds like James Camerons' Aliens, so sue me :-)

You used the left mouse button to click on the map and the hero would walk to that spot. The right mouse button fired your weapons which shot at the position pointed to by the mouse. The game was quite gory, the aliens exploded in a nice big pussy blood splatter. Nice :-)

To the left of the screen was a pop out menu containing icons for different actions the character could do, like, examine, talk etc. Just like the classic Verb, Noun structure of old adventure games.

In another twist of irony, on the next page to this preview was a preview of a game called Heimdal 2, by Core Design. The irony being that I went to work for Core Design after finishing Croc at Argonaut :-)

Labels: ,

Tuesday, September 18, 2007

GPS Routes



After the walk we did the other day to Lathkill Dale, Neil sent me the GPX file from his Garmin GPS system which he was carrying with him during the walk. The system basically stores your position on a fixed timescale so it records your course. Neil uses this for matching up photo's from his camera with GPS locations. Not something I particularly need to do, but I found this cool website that will read the file and plot the course on a google map. Just click on the image above to see the full 8.5 mile route we did on Sunday.

I feel an interesting programming pet project coming on :-)

Labels: ,

Sunday, September 16, 2007

A Blast From The Past


I was sent a link by a friend the other day to some screenshots of a game I worked on years ago at Argonaut Software. The game was called Croc - The Legend Of The Gobo's; On the old GameBoy Color handheld console.



My role on the game was as a software engineer. My main task was writing the games editor. This allowed the designer to build the levels out of tiles, set collision zones on tiles and in game characters.


Becuase the GameBoy Color was a ROM based games machines. The game couldn't load up individual files. This meant that my editor had to convert all the tiles/graphics/maps into Z80 machine code. This was a tricky task, but one that was fun to work on.



The graphics were done by my long time school friend Chris Rundell. He worked at Argonaut as a contractor at the time. The GameBoy Color was a very limited machine graphically, but Chris's art style meant he could make the graphics look like they had many more colors than there were.



The game design was done by Anna Larke. She was responsible for designing the levels and building the maps using my editor, out of the tiles that Chris created.


All sound and music was created by Juston Sharvona. After all the testing we did on the game, the main theme tune still makes me shudder. Not because it is bad, but because I listened to it so many times.



It has been good to get hold of some screen shots of this game. This was back in the good ol days of games creation. Back when it was fun. Brings back a lot of memories looking at the old screenshots. I think I still have a copy of the ROM up in the loft. I still remember fondly our arguments with Nintendo and how they wanted us to remove some graphics of up-turned crucifixes from Baron Dante's Castle. :-)
There is an entry for this game on Moby games.

Labels: ,

Thursday, September 13, 2007

Good Cryptography Books

I have recently read 2 very good books on cryptography. They are not hardcore techie books but more in the realm of history/popular science. The first book (The Code Book by Simon Singh) was recommended to me by Carl a colleage at work. The book is a historical account of the history of code breaking and cryptography. I would say that this book is the baby brother of David Kahns 'The CodeBreakers', which is on my reading list, but weighing in at 1200 pages might take me a while to finish.


The book starts off in the day of Mary Queen of Scotts and takes you on a tour of warfare in the past and how codes and codebreaking helped. The book also gives a lot of information on the cryptanalysis of a lot of these algorithms, including a good description on frequency analysis. There is a lot if information about poly and mono-alphabetic ciphers, as well as homophonic ciphers. The section on how Charles Babbage cracked the Vigenere cipher was also very good. If you're interested in the implementation of some of these ciphers refer to a previous post of mine called 'Fun With Cryptography' where I posted some source code.

The book also discusses modern cryptography. By modern I mean upto the 70's and 80's. Particular highlights are the discussion on the invention of the Diffie-Hellman key exchange algorithm and DES. It is interesting to see how invasive the NSA were, who back then was a much more secret organisation. The final section of the book is a very brief wirlwind tour of quantum cryptography.



The second book I have read recently is called Crypto by Steve Levy. This book is also a historical account of cryptography but concentrates more in the discoveries from the 1970's. Again this discusses the Diffie-Hellman key exchange algorithm and the public key protocols designed by RSA. Both books where excellent and if you are even slightly interested in the subject then these books are a good place to start. They are not too technical so can be understood by people with a non computer science / mathematics background.

Labels:

Sunday, August 19, 2007

J2ME Games


The other day at work we had an interesting meeting/demo about mobile phone software development. This reminded me of when I wrote a game for mobile phones on the j2me platform. It was a fun puzzler where you had to swap gems around on a board to make a line of 3.
It's a very simple concept but it was highly addictive. I remember Amanda got quite addicted to it whilst I was writing it. The good ol days :-) It is available on nokia series 60 based phones from mobilefun.co.uk.
For the geekier readers it was a j2me java application written for the midp 2.0 platform. I coded it using Borland JBuilder. This was a common development environment to use before Eclipse was more widely used for mobile development. The whole game including graphics had to fit into a 64k jar file!!!.
It was a fun project to work on, but its a line of work that doesn't pay too well. Oh well.
To play the game you need one of the following Nokia phones:
Nokia 3230, 3250, 3620, 3650, 3660, 6260, 6600, 6620, 6670, 6680, 6681, 6682, 7610, 7650, N-Gage, N-Gage-QD, N70, N70-1, N72, N91

Labels: ,

Friday, August 03, 2007

How to get your Mac address with C#

The other night I was playing around with some code and I need to be able to extract the users MAC address for their machine. A MAC address is a number that uniquely identifies your network adapter in your machine. This can be achieved by using the ManagementClass from the System.Management namespace in .NET. The members of the ManagementClass enable you to access WMI data using a specific WMI class path. More information on the Win32 classes accessed via WMI can be found here. This example uses the WIN32_NetworkAdapter part of WMI. More information about data passed back can be found here.

The code below is all you need to extract the MAC Address. You will need to include a reference to the System.Management assembly in your project.

private string GetMacAddress()
{
ManagementClass managementClass =
new ManagementClass("Win32_NetworkAdapterConfiguration");


ManagementObjectCollection managementObjectCollection
= managementClass.GetInstances();


foreach (ManagementObject mo in managementObjectCollection)
{
if ((bool)mo["IPEnabled"] == true)
{
return mo["MacAddress"].ToString();
}
}


return string.Empty;
}


Labels:

Thursday, August 02, 2007

Good WCF Programming Book


I have recently just finished reading the above book on WCF programing by Juval Lowy. This book is a very good read. I spent a while looking for a book that doesn't just rehash the MSDN documentation and this book fits the bill. As well as telling you how to do certain things in WCF, it also spends a lot fo time telling you why you would want to do those things. The only bad comment I have about the book is Juvals points raised about MessageContracts. He states that:
"Any professional WCF programmer should use MessageContracts only rarely,
and therefore I will not discuss them in this book."

This is fine, but he doesn't explain why you should only rarely use them. When I find out the reason, I'll post back here. But apart from this minor gripe, the book is very good. You can read a sample chapter of the book from the O'Reilly Website if you want to check it out.
I also have Juvals Programming Components book too, but I havn't read this yet.

Labels:

Sunday, July 29, 2007

4 Tenets or Service Oriented Architectures

I was chatting to an ex colleague the other day, and he was saying that at work he was about to start working on a set of web services for one of their web projects. The conversation carried on down the web services design route for a bit. One comment that made me wince a little was, “they are just like online dynamic link libraries”. Well they could be seen as online dll’s I guess, but to produce a proper service oriented architecture you need to follow a few firm rules / principles. It isn’t the first time I have heard of web services described in this way, so I thought I would add a post briefly explaining the 4 tenets of services oriented architectures.



Service boundaries are explicit

Any service is always confined behind boundaries such as technology and location. The service should not make the nature of these boundaries known to its clients by exposing contracts and data types that betray its technology or location. Adhering to this will make aspects such as technology and location irrelevant. Another way of thinking about this is that the more the client knows about the implementation of the service, the more the client is coupled to the service.




Services are autonomous

A service should not need anything from its clients or other services. A service should be operated and versioned separately from other services. This will enable the service to evolve separately from the client.





Services share operational contracts and data schema, not type and technology specific meta data

Any data the service decides to expose over the service boundary should be technology neutral. The service must convert any technology specific data to some neutral representation. A service must also not expose any local implementation details such as instance management or concurrency. A service only exposes logical operations.




Services are compatible based on policy

A service should publish a policy indicating what it can do and how clients can interact with it. Any access constraints expressed in the policy should be separate from the service implementation details. Not all clients can interact with all services. It is perfectly valid to have an incompatibility that prevents a particular client from consuming the service. The published policy should be the only way a client can decide if it can interact with the service.

These are the main published rules around web services. There are also some other principles that are good practice to follow: First, services should be secure. Even if this only means securing the transport (ie SSL). The client should also have a way to authenticate with the service.

Services must leave the system in a consistent state. If an operation fails part way though, the service should be able to leave itself in a consistent state. This could be via transactions or any other method of maintaining consistency.

Services should be thread safe and designed so that it can sustain concurrent access from multiple clients. Services should also be reliable (yeah seriously). When a client calls a service, it will always know in a deterministic manner if the message was received. Messages should also be processed in the order that they were sent. As well as being reliable, the service should also be robust enough to isolate its faults, preventing them from taking down itself or other services. Well I hope that clears that up :-)

Labels:

Sunday, July 22, 2007

C# RSS Feed Generator Library

You can download the MSI installation package from here.


A while ago I wrote a library in C# for creating and saving RSS xml feed files. I recently dusted off this code and gave it a tidyup.

RSS (which stands for "Really Simple Syndication") is a family of web feed formats used to publish frequently updated content such as blog entries, news headlines or podcasts. An RSS document, which is called a "feed", "web feed", or "channel", contains either a summary of content from an associated web site or the full text. RSS makes it possible for people to keep up with their favorite web sites in an automated manner that's easier than checking them manually.

RSS content can be read using software called a "feed reader (such as Outlook 2007)" or an "aggregator." The user subscribes to a feed by entering the feed's link into the reader or by clicking an RSS icon in a browser that initiates the subscription process. The reader checks the user's subscribed feeds regularly for new content, downloading any updates that it finds.

I will not go into the full RSS spec in this post, but you can read about it at this following address : http://cyber.law.harvard.edu/rss/rss.html

The library is very easy to use. The following code shows its use in the most basic form creating an RSS channel and item containing just the mandatory fields.

RssLib rss = new RssLib();
rss.Channel = new Channel("Steves News", "http://www.stevehaunts.net", "Steve news and related bits and
pieces.");

rss.AddItem(new Item("Cat Saved", "A black cat was today saved from a tree."));
rss.SaveRssFeed(Path.GetFullPath("/test.xml"));

The library handles conversion from the .NET DateTime object in to the RFC882 date specification required by the RSS feed specification. The library also handles converting langauge codes into the RFC1766 language specification.

I have included an nUnit test suite with the library containing over 100 unit tests, so if you want to refactor any of the code you can do so with confidence using the unit tests.

The code is written in C# under the .NET2 platform. You will need Visual Studio 2005 to open up the solution file. To run the unit tests you will need nUnit.

You can download the MSI installation package from here.

Labels:

Sunday, July 01, 2007

Fun With Cryptography


Last year I watched the Thomas Harris film adaptation of his World War 2 novel, Enigma. The film was about Alan Turin's work in cracking the German Enigma cipher system. This got me thinking about different type of text encryption techniques. So one weekend when my wife was away on business, and I had nothing else to be getting on with, I started writing some simple text encoding routines.

The first routing in the sample code is a monophonic substitution cipher. This simply substitutes a different letter for each letter of the alphabet.

MonoSubstitute mono = new MonoSubstitute(KeyType.USER_KEY, true);
mono.PlainText = ”Text to encrypt”;
mono.Key = "This is my key";
mono.Encrypt();
mono.DeCrypt();


Next up we have homophonic encoding. This assigns 2 values per letter of the alphabet. This helps even out the spread of characters to make the encoding more secure against attacks. Each letter of the alphabet is assigned 2 numbers.

HomophonicCoding homo = new HomophonicCoding(KeyType.USER_KEY);
homo.Key = "This is my key";
homo.SubKey = "This is my sub key";
homo.PlainText = ”Text to encrypt”;
homo.Encrypt();
homo.DeCrypt();


When a monophonic cipher is used, the frequency histogram of the cryptogram is made flatter by increasing the size of the alphabet. This ensures that more than one ciphertext character may represent the same plaintext character. However there is always the danger of an attacker compiling a dictionary of known plaintext and ciphertext pairs for a given key.

Another way of achieving the objective of flattening the frequency histogram is by the use of a polyalphabetic cipher. When a polyalphabetic cipher is used, the ciphertext character replacing a particular plaintext letter may vary through the cryptogram and might, for instance, depend on its position in the plaintext message or the content of the plaintext that precedes it.

The final algorithm shown in the sample is the Vigenere cipher, invented by Blaise de Vigenere, a 16th century French diplomat. The Vigenere uses a vigenere square to perform encryption. The left hand (key) column of this square contains the English alphabet, and for each letter, the row determined by that letter contains a rotation of the alphabet with that letter as the leading character. So that each letter in the left hand column gives a Caesar cipher whose shift is determined by that better.

VigenereCipher vig = new VigenereCipher();
vig.Key = "This is my key";
vig.PlainText = ”Text to encrypt”;
vig.Encrypt();
vig.DeCrypt();

Also included within the sample source code is a combined cipher that uses a combination of all 3 encryption type. I’ll leave it as an exercise for the reader to see how this all works.

CombinedCipher com = new CombinedCipher();
com.Key = "This is my key";
com.PlainText = ”Text to encrypt”;
com.SubKey = "This is my sub key";
com.Encrypt();
com.DeCrypt();


I’m sure I don’t need to say this, but I will mention it anyway. These are very old types of text encryption that by todays standards are not secure, so please don’t use them for encrypting anything important. The code was only written for fun.

The source code is written in C# and the solution file was created with Visual Studio 2005. There are some unit tests in CryptTests.cs. These can be run using the NUnit test runner or the Resharper test runner.

Labels:

Pipeline Execution Pattern


Click here to view larger UML diagram.


This is the first version of a library for implementing a pipeline execution pattern. I originally wrote this library a couple of years ago and recently found it on one of my backup discs. So I dusted it off, tidied it up, and decided to release it as a code example.

This is only the first version and is by no means perfect; I have lots of ideas that can be added to this pattern to improve it.
The code is written in C# and the solution file is for Visual Studio 2005. If you want to run the unit tests you will need either NUnit, or the Resharper test runner.

Pipelines

A pipeline consists of a series of nodes that are registered with the system. Once the nodes are registered, you can assemble the nodes in any order to form a pipeline. Once the nodes are assembled into a pipeline, you call execute() and the nodes will be executed in order.

You might be wondering what the point of this is, but a pipeline allows you to break a complex computational task down into smaller discreet steps. Before you run the pipeline you can set some initial xml data to the pipeline that is passed in between the nodes as they execute. This essentially allows each of the nodes to talk to each other.

Pipeline Configuration

Via Code

A pipeline can be configured in 2 ways, through code, or via an xml config file. First we will discuss setting up a pipeline via code. To create a node you need to derive from the common Node base class.

internal class TestNode : Node
{
public TestNode(Pipeline pipeline)
: base(pipeline)
{
}

public override bool Verify(XmlDocument doc)
{
return true;
}

public override bool Execute(XmlDocument doc)
{
return true;
}
}

When you derive from the base class you much override 2 virtual functions, Verify, and Execute. When a pipeline executes, Verify will get executed first for a node. This give you a chance to do validation and integrity checks on the node, this might be examining the data passed into the node. If Verify fails you return false and the pipeline stops executing. If Verify returns true, the pipeline then calls Execute on the node. This is where you perform the actual node task.

To use your nodes with the pipeline you must first register the nodes. You do this as follows:

Pipeline pipeline = new Pipeline();
pipeline.RegisterNode("node1", new node1(pipeline));
pipeline.RegisterNode("node2", new node2(pipeline));
pipeline.RegisterNode("node3", new node3(pipeline));


You first construct an instance of the pipeline class, and then you create instances off you node. You must pass the pipeline instance into the node constructor. This gives the node access to the error reporting method of that pipeline instance.

Once a node has been constructed you must call RegisterNode on the instance of the pipeline. This makes that node available to the pipeline.

Now that you have registered your nodes, they are now available to be added into a pipeline. This is done a follows.

pipeline.AddNode("node1");
pipeline.AddNode("node2");
pipeline.AddNode("node3");
pipeline.AddNode("node1");

You will notice that node1 has been added twice. This is perfectly fine. A node can only be registered once, but it can be added to the pipeline as many times as neccessary.
To execute the pipeline you call:

pipeline.Execute();

Via XML Config file

You can also add nodes to a pipeline via a config file. At the moment you still need to register the nodes in code, but the config file will add the nodes to the pipeline. A future enhancement to this code will be for node registration via the config file. You load a config file as follows:

pipeline.LoadPipelineFile("example.xml");

Look at the example.xml file included in the MSI package.

As you can see, inside the pipeline element we have a Nodes section. Within here individual Node tags specify the running order of the pipeline.

You will also notice we have parameters setup in the first node. This allows you to configure parameters that are available to the node. These parameters are stored in the NodeParams part of a node. To extract the parameters inside a node you do the following:

String tolerence = Params.Find("tolerence")

Passing Data through the pipeline.

When you create the pipeline you can add data that will get pass through the pipeline when it is executed. This data is available to each node to change as necessary. This data is passed into both the Verify method and Execute method as a standard .NET XmlDocument object. See the .NET documentation on how to extract and add data to an XmlDocument. Data is added to the pipeline as follows:

pipeline.SetData(xmlData);


Object Cache

As well as passing an xml document to each node, a pipeline provides a central object cache where a node can store data to be retrieved by each node. This is useful if you want to store temporary data that should not be stored as part of the xml document. This also aids performance because serializing temp objects to xml can get slow if done a lot. A node can cache data like the following:

CacheObject("myobject", myObject);

Reporting Errors and Warnings

As each node executes you store a list of error and warning messages. When the pipeline finishes executing, either successfully or unsuccessfully, your program can present the list of errors and warnings to the user. For a node to add errors and warnings you do the following:

AddWarning(“Warning, something is not right.”);
AddError(“Error, something has gone wrong.”);


Summary

I hope you find this pattern and code useful. As I mentioned earlier I originally wrote this a few years ago so have only recently dug it out and updated it. I have more ideas I want to incorporate like:

- Node registration via config file.
- Nodes as separate plugin DLL’s which are automatically loaded by the pipeline manager.
- Node branching.

I recommend you load up the code and dive in, it’s not that complicated to find your way around. In the solution there is a test project that contains a load of NUnit unit tests. So if you want to fiddle with the code you will easily be able to tell if you have broken anything. The unit tests also make for good examples in how things are working. Have fun.

Download MSI Installer for Source Code

Labels:

Categories

Now that Google has added categories to this blog site I can now properly segregate all my posts into different sections. To the right of this post you will see a categories section. You can use this to go to categories that are of most interest to you. So for example, family and friends will most probably be interested in the out and about site. Fellow musicians will most probably only be interested in the Circuit bending and music section.

Labels: , , , ,