Self Replicating Programs – Virus !!!

Hi Everybody !

I hope you all had found my previous post worth reading… ! Well… This time I’m here with a new topic…. Its called Self Replicating Programs… Or in simple words, what we use to call them — Computer Virus !!

Before I proceed, let me just brief you about what exactly a virus is ! A computer virus is a computer program that can copy itself and infect a computer without permission or knowledge of the user. The history of computer viruses dates back to 1949, when theories for self replicating programs were first developed. First “on the wild” virus came into existence in 1981. These viruses, named Apple Viruses 1,2 and 3 were found on Apple II operating system. Since then, viruses are evolving with time getting new enhancements each time. For a complete list of virus timeline, I suggest you to visit this site.

Let me take you the era when computers were like a science fiction stories ! Early computers were so expensive that it was unthinkable that you would have an entire computer to yourself. Instead, many people would use a single “timesharing” computer system. Unfortunately, early primitive operating systems lacked technologies like memory protection. If a program accidentally malfunctioned, it would sometimes end up crashing other programs, or the operating system itself ! However, in those days, computer programmers had a strange sense of humor. Instead of crashing an actual computer system (That would cost their job !), they made a virtual computer system and allowed malicious programs to run in the virtual environment. This prevented the actual machine going down — much like the Java virtual machine in many web browsers today. The game became known as Core War, named after the “core memory” used in early computers; it was first described in detail by A.K. Dewdney and D.G. Jones in 1984. The virtual machine used for the game had a very simple instruction set called RedCode. Competitors would write RedCode programs that attempted to copy themselves elsewhere in memory and then run the extra copies. Programs would also try to find and overwrite competing programs and make them crash. Some Core War code would carefully take over the competing software, stealing its allocation of CPU time like a virus. Eventually, the last program left running would be the winner.

This game was quite famous in late 80’s.

SOME INTERESTING STUFF

Many years ago, a young MIT computer hacker, Tom Ray, had introduced the idea of self-replicating computer code in a virtual machine. He wondered if he might be able to build some kind of artificial life kind of software that would let him run experiments. He built a computer program to model a virtual computer similar to the one in the Core Wars game, and called his virtual world Tierra. However, Ray added a new feature to the virtual world that had been missing from Core Wars: Mutation !!!

Before proceeding, let me first clear a few basic concepts of computer programming. Every computer is normally programmed in textual languages of words, symbols and numbers that humans can understand, like C, Java and BASIC. However, internally the machine only understands a much simpler language of binary numbers. A language of 0 and 1. To add two numbers together, you might need to read them from memory into spaces called registers, add the two registers together, and then write the result out to memory again. Each of those small steps would be represented by a series of binary numbers.  It would be possible to code any application in binary language, provided the program is fairly small. programs in Core Wars and Tierra are only a few tens of bytes, maybe a couple of hundred at most, and are written in machine language.

Now back to track ! Mutation : Ray, in his virtual system, altered the Tierra system to simulate a computer with a slight flaw. Every now and again, the machine code instruction which copied data between memory cells would randomly flip one of the bits during copying. If the data being copied was the machine code of the program itself as it tried to reproduce, the result would be a slightly different program…… Yes you guessed it correctly… Mutation ! This very phenomenon is what is called Mutation.  Modern computer systems of today special error-correcting memory is used to avoid bits getting flipped. This is done because if you flip bits in the machine code of a piece of software, it will almost certainly crash !

Ray decided to start his Tierra system off with a population of the most simple programs possible. He wrote a piece of code that simply copied itself elsewhere in memory then spawned the copy. It was 80 bytes long, so he named it 80. He spread a few 80s through the Tierra system’s memory, and started the clock.

For the first few thousand generations, nothing much of interest happened. There were a few minor mutations that didn’t break the code, but that was about it. Before long, though, there were a number of 81s–mutants with an extra byte of program code. A little later, a 79 appeared (Program with 79 bytes). Because the 79 had one less byte of code, it took less time to reproduce, and was more successful than the 80 or 81. It began to take over the Tierra ecosystem.

Next, something astonishing happened. A 45 appeared (Program with 45 bytes). Ray was initially mystified; he’d written the simplest code he could imagine and it was 80 bytes. A 79 seemed reasonable, but how could a 45 reproduce in only just over half the space? Examining the code of 45 provided the answer with a new surprise !! 45 was a parasite: instead of reproducing itself, it hunted for the reproductive code of an 80, then called that code. It was almost like a biological virus, which reproduces by inserting its DNA into a host cell and using the cell’s reproductive apparatus to build more viruses.

No parasite code had been written at any stage in Tierra’s development, and the system had not been designed to support parasites; the fact that one program could make use of code in another was an accident. Yet the system had reproduction, death, natural selection and mutation, and that seemed to be enough to cause parasites to appear from nowhere. Suddenly Tierra was an ecosystem in balance. If there were too many 45s, then the 80s would die out, unable to compete; and then the 45s would die out too, unable to reproduce without a host !

It turned out that the 79s were immune to the 45 parasite. Ray placed some 45s in a Tierra world heavy with 79s, and soon a new 51 parasite (A program with 51 bytes) appeared which was able to use 79s to reproduce. If the system was left running long enough, parasites of parasites began to appear.

Then came another surprise: after a long period of mutation, another new program appeared. This was a 22 byte code, named 22. This was completely self-contained, not a parasite. Somehow Tierra had evolved a program that was smaller than any human being had managed to come up with.

The power of evolution had been demonstrated, but Ray was curious to see which elements of the system were required for evolution to work, and what ranges of frequency of mutation resulted in rapid evolution. He tried turning off mutation completely, out of curiosity–and was amazed to find that evolution carried on happening anyway!

It turned out that sometimes, two programs attempting to reproduce would choose the same location for their offspring, and would interact during reproduction. One of the programs might be overwriting the same memory as the other, slightly behind, and then die from old age or be killed by another program. The result would be a hybrid, with part of the code of one program and part of the code of the other. Similar hybrids would occur if a parasite was busy reproducing using a host program, and that host program died.

Even today viruses are able to protect themselves against latest anti-virus due to this mutation factor. This helps viruses to be untraceable while still keeping their code intact.  This reminds me of a few lines by Fred Cohen – Father of computer viruses.

According to him, “No infection can exist that cannot be detected, and no detection mechanism can exist that can’t be infected. This result leads to the idea that a balance of coexistent viruses and defenses could exist, such that a given virus could only do damage to a given portion of the system, while a given protection scheme could only protect against a given set of viruses. If each user and attacker used identical defenses and viruses, there could be an ultimate virus or defense. It makes sense from both the attacker’s point of view and the defender’s point of view to have a set of (perhaps incompatible) viruses and defenses.”

Sounds something like the movie “Matrix” …. ???? Those who have seen the film would be able co-relate this with what was shown in the film… In this post, I’ve tried to show how the early viruses evolved over time and implementation of anti-virus programs against them…  In my next post, I’ll discuss about the Red Pill and Blue Pill concepts. Keep looking………

Enjoy !

Similar Posts you might be interested in:

Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • LinkedIn
  • MySpace

2 Responses to “Self Replicating Programs – Virus !!!”

  1. w0lf says:

    wow!!! That was a nice read. You took me back to those olden days and reminded me of my history classes :)

  2. Ne0 says:

    Thanks w0lf ! I just tried to make it a bit interesting such that people reading it should not get bored… Thanks once again.

Leave a Reply