Archive for the ‘ Development ’ Category

Self Replicating Code

For a class recently the teacher challenged us to write a code snip-bit that would be self replicating. By that I mean write a program that when executed would write out its own source code. This is a bit harder than you’d initially think it to be. My first attempt tried to store the source code within the program when execute it would output what was stored within. However this creates a chick and egg problem. The source code contains the source code. Something that at first stumped me. Then I remembered Stringification in the C preprocessor and I came up with this:

#include “stdio.h”
#define M(Code) main(){FILE* fp = fopen(“source.c”, “w”);fprintf(fp,”#include \”stdio.h\”\n#define M(Code) %s\nM(%s)\n”,#Code,#Code);fclose(fp);}
M(main(){FILE* fp = fopen(“source.c”, “w”);fprintf(fp,”#include \”stdio.h\”\n#define M(Code) %s\nM(%s)\n”,#Code,#Code);fclose(fp);})

This is a pretty cute program if I can say so myself. When its ran it will create a file called source.c that will be exactly the same as the code above. You could even recompile source.c and it will create another source.c. You should attempt to do this on your own to see if you can come up with other cool ways of doing it.

Download: SelfRep.c

Consider both sides

I was recently watching some research project proposals at my university. One of the proposals caught my eye, it was a way to stop common cheating techniques for page rank. At first glance the proposal has some good merit, the system would stop the current techniques used. However the problem was that they did not take into account what new problems they would introduce.  The actual proposal is still private so I can not talk to much about the details.

It is very common to come up with solutions that fix very common bugs. What is equally as common is creating new bugs that are as bad as ones that were corrected. When fixing security vulnerabilities the fixer must consider both what is fixed and what bugs the fix will introduce.

Twitter can be neat

If  you are like me you don’t exactly see the usefulness of the social networking site Twitter. After reading a recent wired article I can not better see that usefulness. There appears to be some pretty clever people connecting common house hold devices to Twitter.

This really isn’t all that new of a concept however. People have been connecting bots to IRC for control for a very long time now. I would suspect similar devices have been plugged into IRC. I wonder about the secuirty behind putting so much control of your house onto the net. Losing control of your own account could give an attacker control of say your air conditioning and drop your house to 60 degrees. Causing your electric bill to ski rocket.

Great C Tutorial

Dr. Dave Marshall at Cardiff School of Computer Science has written a great C tutorial. This tutorial is mostly aimed at UNIX C developers and covers the basics of C programming to advanced multi-threaded application development. This is the tutorial that I used to learn C and I still open it up whenever I need to look up something new or need a quick refresher on something. Unfortunately it appears that Google keeps burying the link so I thought it would be helpful to others that are looking for in my opinion the best C tutorial available online.