A Brave New World – Learning Rust

Hello, world.

It’s great to be back writing blog posts again and it has been far too long since my last one. I have some excuses, but my lack of posts is mostly owed to health issues and lack of motivation. I plan on addressing the latter of those two.

For the past few weeks I have been working on a virtual machine written in C#. I had intended on writing some blog posts about that but instead I have a new topic in mind. Instead I have decided to write a few blog posts about my path into learning the Rust programming language. I will go through how to get Rust set up and running in Visual Studio code and we will go from there.

Quickly Find Day of the Week – C#

Hi all!

This is just a random post to show off something new I found. I don’t claim credit for this algorithm and if you’re curious as to how it works then this Wikipedia article may be of interest to you. This post has a good explanation of why the algorithm works in the first place.

Given a date the following function would give a string donating the weekday on which a given date will fall:

public string FastDayOfTheWeek(int year, int month, int day) {
    string[] days = new string[] { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };
    if (month < 3) {
    int weekday = (year + (year / 4) - (year / 100) + (year / 400) + (int)("032504514624"[month - 1] - 48) + day) % 7;
    return days[weekday];

If you run the function for the 1st of March 2020 it will give a Sunday. This is the correct answer. This function works backwards and forwards in time as far as I can tell.

Another interesting thing about the given formula is that it could easily be memorised and may make for a nice mathematical party trick.

Hopefully someone out there will find this useful and or interesting.

Teresa May’s “Lets Censor The Internet” Nonsense

I don’t plan on posting many of my political views on this blog but I feel this one is important enough that I can’t just sit by any be silent.

After the recent terror attacks on London, Teresa May is once again attempting to push her own political agenda that the government needs more power to police the internet in order to prevent these sorts of things happening.

Oh boy, where do I start on this one?

Teresa May wants governmental agencies to have access to everything so that there are “no hiding places for terrorists to hide”. This sounds like a good idea in principal but there are some deeper issues that make it not only irresponsible but impossible. The terrorists were already known to the police at the time of the attacks so the intelligence services would already have had access to as much information about them as was needed to complete their jobs. Let’s ignore this fact for now.

I’m sure everyone is aware of the recent our break of malware that severely impacted the NHS infrastructure in England and other institutions around the world. The underlying technology used by the malware to infiltrate systems was originally developed by the NSA and kept hidden from the world until it was released by a hacking group called The Shadow Brokers. The NSA had kept this exploit hidden so that they could leverage it for their own operations. In effect there was a backdoor written into Windows (albeit an unintended one) that could be leveraged by anyone that knew how.

Imagine if the government started to intentionally add back doors to existing technology and infrastructure to enable them to spy on whatever data may be contained. The government could access all the data at their own discretion but so could anyone else found the backdoor. A door can be opened with anyone by the key and we all know that keys can be lost, stolen or misuses.

Encryption technology is the backbone of the internet – it ensures that everything from PayPal payments website logins are secure and safe – I’m sure you will have seen the padlock in your browsers address bar.

Encryption is, for the most part, a clever application of mathematics designed to perform operations that are quick to calculate when certain parameters are known but exceedingly difficult to forcibly break if one or more are not. It’s probably impossible for most of the current technology in use have back doors added. This much is evident to anyone with some basic understanding of how the technology works. Would this mean that these technologies would no longer be usable if Teresa had her way? Would it mean that we would need to use government approved insecure variants?

This nonsense has to stop. The government needs to stop using tragedy as a hammer to try and push forward it’s own moronic agendas.

The technology should be left to the experts – the government doesn’t fall into this category.


Learning Japanese – Some Thoughts

For a long time I have been planning to learn Japanese and I have attempted to do so on and off for a little over a year.

My main drive for this has been my love for the Japanese culture and more specifically my interest in anime.

In my various failed attempts to learn the language I have learned a few things that I was ignorant of during my initial attempts:

  • In order to get a good grasp on the spoken language it is very helpful to learn the written forms first.
  • Learning the written forms of Japanese is more complex than one would initially expect as Japanese has at least three written forms that are used interchangeably.
  • The written forms of Japanese are very unlike English and the sentence structure is completely different.

To this end I have decided to write a program that will help me learn the basics Japanese characters – starting with Katakana and Hiragana. I may or may not attempt Kanji after I have some success with the other two.

The program will break down the written forms into categorized subsets, giving options to choose which of the written forms and subsets to use. It will display a random character and prompt the user to enter it’s Romanji variant.

I have other plans for the tool later but I need to start somewhere!

Long Hiatus

Hello one and all!

It has been quite a while since I last made a post here. In the near future I plan on starting blogging about my experiences in programming (and other related topics) again. Hopefully I will be able to provide some information related to the “Learning Japanese” program that I am slowly putting together.

More to come in the near future, wish me luck!

Setting up a local web server with WAMP

Hi everyone.

This is something I recently had to do so I figured I’d share this with anyone else out there that may want to know. For a long time I’ve wanted to setup a local web server to build and test sites locally without the need to continually upload the files (and as a plus of course, local files are easier to back up). After some research and playing this is the process I eventually came up with to get the optimal configuration for what I need.

Firstly it was a choice between XAMPP and WAMP. I ended up choosing WAMP because I didn’t need Perl. Other than that they seemed about equal.

After downloading the EXE I installed it (obviously) and copied the files to the www folder (which is located in C:\wamp\www\ by default). I noticed a few problems right away however. .htaccess rewrites didn’t work as the module was enabled. To re-enable it I clicked on the icon in the task bar, clicked on “Apache”, then “Apache modules” and selected “rewrite_module”. I then had to restart the server by clicking on the icon once again and selecting “restart all services”.

That fixed most of the rewrites not not all of them worked. It turned out this was because I needed to add a virtual host for the project. Luckily this also wasn’t difficult to achieve.

First you need to pick a name for the virtual host, I picked tnda because that was the name of my project. That name will be used in my examples here. After picking the name you must then open the following file: “C:\Windows\System32\drivers\etc\hosts” in your favorite text editor. At the bottom of the file you need to add a line like this, substituting tnda with your chosen project name. Note that this name CANNOT include spaces! tnda

After doing that, save and close the file.

Next we need to modify the Apache virtual hosts file. This one is also luckily pretty simple. In the default WAMP install it should be located here:”C:\wamp\bin\apache\Apache2.2.21\conf\extra\httpd-vhosts.conf”. Of course the Apache version may vary depending on when you installed the program. Open this program in your favorite text editor and at the bottom of the file you need to add this. Substitute the path here “c:/wamp/www/tnda” with the path to the folder in which your project lies. You also need to replace the server name (TNDA here) with the name chosen in your hosts file above.

DocumentRoot "c:/wamp/www/tnda"
ServerName tdna

Options Indexes FollowSymLinks
AllowOverride All
Order Allow,Deny
Allow from all

Save and close the file. Now you again need to restart Apache. You will now find that you can use full mod-rewrite rules on that project and as a plus you’ll be able to use http://projectname to access the resources quickly locally when the server is active.

I hope this helps people simplify the process.

File Shredder Code Sample (C# 4.0)

It has been a while since I last posted a code sample. So here is one for you guys to take a look at. Below is the file/directory shredder class.

class FileUtilities
    private static Random Randomizer = new Random();

    public static bool Shred(string directoryPath, bool shouldDelete = true)
        bool success = true;
            string[] files = Directory.GetFiles(directoryPath, "*", SearchOption.AllDirectories);
            foreach (string file in files)
                success &= FileUtilities.ShredFile(file, shouldDelete);

            string[] directories = Directory.GetDirectories(
                str =>
                str.Split('\\').Length - 1
            foreach (string directory in directories)
                success &= FileUtilities.ShredDirectory(directory, shouldDelete);

            success &= FileUtilities.ShredDirectory(directoryPath, shouldDelete);
            success = false;
        return success;

    public static bool ShredDirectory(string directoryPath, bool shouldDelete = true)
        bool success = true;
            DirectoryInfo directoryInfo = new DirectoryInfo(directoryPath);

            string[] directoryBits = directoryPath.Split('\\');
            directoryBits[directoryBits.Length - 1] = FileUtilities.RandomName(directoryInfo.Name.Length);

            string newDirectoryPath = String.Join("\\", directoryBits);

            if (shouldDelete)
            success = false;
        return success;

    public static bool ShredFile(string filePath, bool shouldDelete = true)
        bool success = true;
            FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Write);
            for (long i = 0; i < fs.Length; i++)
                fs.WriteByte((byte)Randomizer.Next(0, 255));


            FileInfo fileInfo = new FileInfo(filePath);
            fileInfo.MoveTo(fileInfo.DirectoryName + @"\" + FileUtilities.RandomName(fileInfo.Name.Length));

            if (shouldDelete)
            success = false;
        return success;

    private static string RandomName(int length)
        string fileNameChars = "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ~!@¤#$£§%^&()+`={}][;,";
        string newFileName = String.Empty;
        for (int i = 0; i < length; i++)
            newFileName += fileNameChars[Randomizer.Next(0, fileNameChars.Length)];

        return newFileName;

The usage calls for these functions as as follows:

bool success = FileUtilities.Shred(@"D:\Temp"); // This method will recursively shred a file / folder.
bool success = FileUtilities.ShredDirectory(@"D:\Temp"); // This method will shred the contents of a folder and the root folder.
bool success = FileUtilities.ShredFile(@"D:\Temp\test.txt"); // This method will shred a specified file.[

I will not go through the code line-by-line to explain it as I feel most of the code is pretty self-explanatory. However if there are any questions feel free to post a comment.

Image Encryption – Completed!

It has been a while since I posted so here is an update for you guys. I should (hopefully) have some time to post some more blog posts detailing my current projects over the next week or so.

My image encryption tool (now known as PGIE – Pretty Good Image Encryption) is finally completed. Anyone wishing to test it is welcome to ask me about it.

Here is a little description that I threw together about the program.

Have you ever had a secret you wanted to hide in plain sight while still feeling secure? If so PGIE is just the program for you!

PGIE uses an innovative and unique mix of new and traditional encryption techniques to store data within a randomly generated pixel image that can only be decoded using a special key file.

How It Works:

PGIE first encrypts the data using a Rijndael symmetric algorithm. The key used to encrypt the data is a randomly generated 1024-bit binary key that is unique to each encode.

The encrypted data is then split into sections and stored within the image. The data is then further secured by modifying the file based on the information stored within the key file. Finally the image is modified to make the original entry point unreadable.

If either the key file or encoded images are modified or damaged then the encryption is one way.

In order for a brute force attack to be successful on this encryption the whole key file image would have to be guessed precisely; every red, green, blue and alpha component would have to match the original in order for the decryption to occur successfully. This would take a very, very long time to achieve with modern computers. See the technical details section below.

Technical Data:

There are a set of 65,535 possible characters that can be used in the encryption key and the key is 1024 characters in length. This means that there are 65535^1024 possible key sets to choose from – one very large number! In the simplest terms possible – if a computer can generate a billion keys per second then it would take far, far longer than the universe has existed to forcibly break.

There are four channels for data within a PNG pixel, red, green, blue and alpha. Each of these can range in value from 0-255. That means that there are 256^4 possible colour values per pixel (4,294,967,296). As the image size grows more pixels need to be correctly guessed in order to decode the image. As such each added pixel makes the image more difficult to decode again, making it virtually impossible to forcibly break.

CSIT – Round 2

Hi everyone.

It has been a while since I last posted. Unfortunately my recent work with CCC has kept me busy and away from my personal projects. However as I currently have some spare time I have decided to revive the old CSIT project and revisit the idea.

I will be starting work on the project in short order (probably tomorrow or later next week). The project will probably still be called CSIT (Complete System Information Tool-kit) and will be similar to the old ideas for CSIT but not identical.

I am currently working on the plans for the design and core code ideas. The project will be based around C++, ASM, C# and WPF.

TNDA – A new tool site for Neopets

Hi everyone!

Just a quick update. Firstly happy new year since this is my first post for this year.

I’m currently working on a new site that will give Neopets users some interesting new tools to play with. I will post more details about it as I decide what features will be there – but in the mean time any suggestions and requests are welcome.

I will be focusing much of my efforts on statistic related items – trying to determine how the random events and so fourth work.