Wednesday, March 14, 2018

Batch Enhance and Resize images using GIMP


GIMP is a free and open source replacement for Photoshop. A great tutorial for enhancing photos with GIMP is described in this link. It makes photos much brighter and vibrant.

steps involved are:

1. duplicate image layer twice
2. Desaturate (Colors -> Desaturate) topmost layer selecting luminosity option.
3. Invert the color of the layer from Colors -> Invert
4. Do Gaussian Blur (Filters ->Blur ->Gaussian Blur), with setting radii as 20 and blur method as RLE.
5. From the Layers panel set the opacity of top layer as 40.
6. Merge down the top layer to the middle layer
7. Change the blend mode of the middle layer (top layer now, after the merge) as 'Grain Merge'.
8. You can test the changes by toggling the visibility of the top layer.
9. Finally merge down the top layer.

That's a lot of steps, to remember. That's where scripting comes to use. (Photoshop has batch mode). GIMP provides 2 scripting languages 'Script-Fu' and 'Python-Fu'. Scripting is also useful to process a folder of photos in a single click, in batch mode.

Script-Fu is evolved from Scheme language, and is bit different in syntax from usual programming and scripting languages. Each statement is enclosed in parentheses, each statement begins with a function or an operator, functions are defined with 'define', variables assigned with 'set!' and variables declared with 'let*'. Edit the script using a text editor and store in '.gimp-2.8/scripts' folder in home folder (in Linux) as *.scm file. First I'll describe a script to resize individual photos and in batch mode from a folder.

(define (my_resize image drawable px)
  (let* ((cur-width  (car (gimp-image-width image)))
         (cur-height  (car (gimp-image-height image)))
         (height (/ (* cur-height px) cur-width))
        )
     (gimp-image-scale image px height)
  )
)

(define (batch_resize file-pattern new-width )
  (let* ( (file-glob-pattern (string-append file-pattern "/*.*"))
  (filelist (cadr (file-glob file-glob-pattern 1))))
   (while (not (null? filelist))
      (let* ( (cur-file  (car filelist))
      (image    (car (gimp-file-load RUN-NONINTERACTIVE cur-file "")))
      (drawable (car (gimp-image-active-drawable image)))
      )
    (my_resize image drawable new-width)
    (set! drawable (car (gimp-image-active-drawable image)))
    (gimp-file-save RUN-NONINTERACTIVE image drawable (string-append (car (strbreakup cur-file ".")) "_resized.jpg") "")
    (set! filelist (cdr filelist)))
    )
  )
)

(script-fu-register "my_resize"
  _"Resize Horizontal"
  _"Resizes horizontal images for photoblog."
  "PG"
  "PG"
  "2018"
  "*"
  SF-IMAGE       "image"          0
  SF-DRAWABLE    "drawable"       0
  SF-VALUE "horizontal pixels" "800"
)

(script-fu-menu-register "my_resize" "<Image>/Filters/Mine")
                       
(script-fu-register "batch_resize"
  "Batch Resize"
  "batch Resizes images."
  "PG"
  "PG"
  "2018"
  ""
  SF-DIRNAME "select directory of images to resize" "~/Pictures"
  SF-VALUE "horizontal pixels" "800"
)

(script-fu-menu-register "batch_resize" "<Image>/Filters/Mine")


In this I've defined two procedures my-resize and batch-resize and registered them using script-fu-register and script-fu-menu-register functions. To be able to use the batch procedure without opening an image, while registering , pass the 6th parameter as "" instead of any image format or as any format with "*" as we did with my-resize function.  To work with currently opened image, pass an image parameter and drawable parameter as first 2 parameters with 0 as default value. 'car' and 'cdr' functions are used to access the list members.

Save this script in the script folder and in Gimp select Filters->Script-Fu->Refresh Scripts. the script will appear in Filter->Mine menu.

Next, I'll write another script to enhance the image using the method I described above. I'll write a script to batch automate, which will first resize the image, and then enhance it, because enhancing will work faster in a smaller size image file.

(define (my_enhance image drawable)

(let* (
(layer2 0)
(layer3 0)
)
    (gimp-undo-push-group-start image)
            (set! layer2 (car (gimp-layer-copy drawable 1)))
    (gimp-image-insert-layer image layer2 0 -1)
    (gimp-layer-set-name layer2 "layer2")
    (set! layer3 (car (gimp-layer-copy drawable 1)))
    (gimp-image-insert-layer image layer3 0 -1)
    (gimp-layer-set-name layer3 "top-layer")

    (gimp-desaturate-full layer3 DESATURATE-LUMINOSITY)
    (gimp-invert layer3)
    (plug-in-gauss RUN-NONINTERACTIVE image layer3 20.0 20.0 1)
    (gimp-layer-set-opacity layer3 40.0)
    (set! layer2 (car(gimp-image-merge-down image layer3 0)))
    (gimp-layer-set-mode layer2 21)
    (gimp-image-merge-down image layer2 0) 

    (gimp-undo-push-group-end image)
    (gimp-displays-flush)
)  
)

(define (batch_enhance file-pattern )
  (let* ( (file-glob-pattern (string-append file-pattern "/*.*"))
  (filelist (cadr (file-glob file-glob-pattern 1))))
  (while (not (null? filelist))
           (let* ( (cur-file  (car filelist)) 
           (image (car (gimp-file-load RUN-NONINTERACTIVE cur-file "")))
             (drawable (car (gimp-image-active-drawable image)))
    )
          (my_enhance image drawable)
          (set! drawable (car (gimp-image-active-drawable image)))
  (gimp-file-save RUN-NONINTERACTIVE image drawable (string-append (car (strbreakup cur-file ".")) "_enhanced.jpg") "")
          (set! filelist (cdr filelist))
        )
    )
  )
)

(define (batch_resize_enhance file-pattern new-width)
  (let* ( (file-glob-pattern (string-append file-pattern "/*.*"))
  (filelist (cadr (file-glob file-glob-pattern 1))))
  (while (not (null? filelist))
          (let* ( (cur-file  (car filelist)) 
        (image (car (gimp-file-load RUN-NONINTERACTIVE cur-file "")))
          (drawable (car (gimp-image-active-drawable image)))
)
(my_resize image drawable new-width) 
        (my_enhance image drawable)
        (set! drawable (car (gimp-image-active-drawable image)))
(gimp-file-save RUN-NONINTERACTIVE image drawable (string-append (car (strbreakup cur-file ".")) "_enhanced.jpg") "")
        (set! filelist (cdr filelist))
      )
    )
  )
)

(script-fu-register "my_enhance"
  "My Enhance" "One touch enhance image" "PG" "PG" "2018" "*"
  SF-IMAGE       "image"          0
  SF-DRAWABLE    "drawable"       0
)

(script-fu-menu-register "my_enhance" "<Image>/Filters/Mine")
                         
(script-fu-register "batch_enhance" "Batch Enhance" "batch enhances images." "PG" "PG" "2018" ""
  SF-DIRNAME "select directory of images to resize" "~/Pictures"
)

(script-fu-menu-register "batch_enhance" "<Image>/Filters/Mine")
                         
(script-fu-register "batch_resize_enhance" "Batch Resize & Enhance"
  "batch resizes & enhances images." "PG" "PG" "2018"  ""
  SF-DIRNAME "select directory of images to optimize" "~/Pictures"
  SF-VALUE "horizontal pixels" "800"
)

(script-fu-menu-register "batch_resize_enhance" "<Image>/Filters/Mine")

As previous script, this adds 3 menu options with procedures to enhance a single open photo, to enhance a folder of photos and to do both resize and enhance a folder of photos in a single step. 

Wednesday, May 27, 2015

How to overcome low memory problems in Android one (Micromax Canvas A1) Phones


Micromax Canvas A1 is a beautiful Android one phone, compact, snappy and delightful. Having come from Samsung Galaxy S3, which I used for 2 years, this phone to my surprise surpassed S3 in performances, almost never hangs, never makes you wait for display to come up, responds almost instantaneously, display doesn't blackout, good battery performance, and good GPRS, GPS performance too.

My only gripe with the phone was low user memory (about 2.6GB) for installing apps. Soon after starting to use the phone, you start getting message "low memory warning: can't install any more apps", while trying to install new apps! Here's how I overcome it, and it's sure to work on any android phone, with suitable modifications. You need to root the phone, which is involved with it's own risks and voids warranty)

Step 1: root your phone.
Rooting involves risks of permanently damaging the phone (bricking) and also voids the warranty. So, unless you have prior experience (of damaging the devices and bearing the stress of unsuccessful attempts) don't try it.

  1. To root, first install ADB and fastboot in your desktop. a quick guide is here. In linux, it's as easy as just as easy as issuing two commands: 
    sudo add-apt-repository ppa:phablet-team/tools && sudo apt-get update 
    sudo apt-get install android-tools-adb android-tools-fastboot
  2. Follow this rooting guide. the steps are: 
  • Enable USB debugging from: settings->developer options
  • Download SuperSU and Phils touch recovery
  • Connect to PC. If a popup appears, click 'always allow'
  • Now, in a terminal type:
    adb reboot bootloader
  • when it reboots into bootloader mode type:
    fastboot oem unlock  and 
    fastboot format userdata  
    (you will lose your data in the phone, so backup)
  • now go to the foder you downloaded recovery and type:
    fastboot flash recovery recovery.img
    then :
    fastboot reboot
  • phone reboots. Now copy the superSu Zip to your phone. and reboot into recovery by:
  • switch off the phone
  • restart simultaneously pressing volume up and power button, then select option recovery and select. 
  • Now select install zip, select the superSu zip file. 
  • Restart. 
Step 2: For some reason, I had to install cyanogenmod ROM. the link2sd app didnt work from stock ROM.
Download cm12.1, GAPPS reboot into recovery, wipe phone, install , first ROM then GAPPS.

Now, reboot into the new ROM.

step 3: partition sdcard
You can do it using desktop. but as i didnt have microSD adaptor, i did it in phone itself! using AParted app.
I had a 16GB SD card, which I partitioned as a 12+GB FAT32 first partition (which is recognised by phone to be used as normal SD card) and a 3+GB ext2 (dont make it ext3 or 4. they dont work with link2sd.) which is to be used exclusively by link2sd and not used by phone ROM at all.

step 4:install link2sd and link all apps.
install Link2SD app. As you open it, it lists apps in your phone, filter those on internal. from menu,  select multi select, select all using menu button, then from menu select Link to SD card.
Now go to settings, select Auto link. and in auto link settings, select all except internal data.

Done! Now apps are actually stored in the second partition of SD card, the phone is made to think, it's in the internal memory itself by placing a simlink in the internal memory. so instead of 2.6GB memory for Apps, Now I have 2.6+3=5.6GB, and low memory warnings are gone for ever!

from Link2SD storage info. 
from settings->storage.


Friday, April 11, 2014

Prof BM Hegde's non-sense about medicine.

Here's a Prof B M Hegde's lecture, in which he says modern medicine is redundant, full of contraditions, and he has found out and researching on wholistic way of healing.


For the start, there are many people out there, who use scientific jargon, scientists' names, theories etc, to sound scientific, and utter non-science. Science is not an absolute body of facts, but an enterprise to learn the objective truth. It need not be done by scientists, in dedicated set-ups. It is the way of shedding personal opinion, doing honest and non-biased enquiry, eagerness to learn, willingness to accept self deceipt, to change ones pre-concieved ideas, in all walks of life, about the world around us.

In his lecture, Prof Hegde, confuses himself, and audience a lot about physics. Non linear mathematics was known since long time, and approximation of physical laws to linear mathematics was because of difficulties in solving non-linear equations, and this approximation of course caused failure of predictions of equations, and they were duely acknowledged. The failure of predictions of physical systems, can be either due to true uncertainity of the system, or deficiency of the theories or mathematics. Quantum physics and uncertainity principle, unlike non-linear equations, introduce true uncertainity,  and the uncertainity is even observer-dependent. Things happen differently, when not viewed! Prof Hegde confuses non-linear equations and quantum physics.

He also confuses relativity and quantum mechanics. Relativity theory doesnt bring in uncertainity, Einstein even said, he thinks 'God doesn't play dice'. and Quantum mechanics doesn't say about conversion of mass into energy. prof Hegde erred on both accounts. He has of course read a few popular science books on 'chaos theory' understood them partly, and forgot the connections and meaning of different theories.

He talks about medicine, that it sees body as a collection of organs, but that, it's a collection of cells, that 'love' each other cells etc. No one will doubt that these are known knowledge, and a doctor doesn't think in terms of organs, and knows, that all substances, drug, food, or other molecules in environment, affect all cells, and molecules of the body.

The concept of bioenergy and biophotonics he talks about is outdated. That, a few people tried to photograph bio-energy, and they did it, and they seem to change with status body is well known. Any body, which is above absolute zero produces radiation, which depends on temperature of the body. This radiation can be photographed, using ultrasensitive sensors. But they are not much useful in diagnosis or treatment, and tell very little more than what can be known otherwise about the body, from sight, touch , temperature etc. The attempt at biophotonics started in 1970, and proven futile science.

Continuing with his holistic medicine, and bioenergy, he then proceeds on to his own technique of healing, using water, nano silver and ?bioenergy. it doesn't sound much logical, but as I have not seen or tested, I can't refute his claims too, and as a true scientist, is eager to see someone study these claims without any bias.

The body has great power to heal itself, which is known, and utlised by modern medicine. The sentences such as whether a heart can be replaced on a dead body is non-sense. He can't do it either using his machine of bioenergy. The concept of dealth as a singular event of bio-energy leaving body is not logical. death is not a single event. different parts (or cells if you like to call it that way) die at different times, we even some times carry 'dead' cells (gangrene foot). We all know cornea can be taken out some time after  a person is dead, for 'eye transplant'. Does that mean, the cornea retains it bioenergy?

Repeating my sentence, Prof Hegde caught a few sentences and quotes from popular science books, and is misleading people on what's scientific medicine.


Sunday, January 19, 2014

Why do we do Good?

Biologically, what prompts us to consider some things as good and drive us to do those things? Like in other fields, science does answer the question of morality and ethics.

The biggest advance in biology since Darwin was the proposal of 'selfish gene theory' by Richard Dawkins. Even before Darwin, biology was searching how individual organisms evolved, and Darwin in his master stroke described how nature, though subconsciously, selected the most adapted organism to its surroundings, from a group of random variations in successive generations. Richard Dawkins showed that individual organism is only a temporary association between genes, in a constantly flowing digital river of genes, in which they mix and match and form temporarily associations, and that evolution works at genes' level.

There's only a faint definition of organism. For example, many of the commensals, that's friendly organisms residing inside another organism, can be regarded as belonging within that organism itself, since they often dont have independent existance. There are many microbes residing inside our body also, and they simply propagate between people, and never exist outside them. The extreme form of this symbiosis is, within our individual cells, where there are organelles like mitochondria, which were independent organisms at the start of life, and then, became permanently to reside inside other cells, and now they are not considered as separate entity at all. We often refer to 'our' mitochondrial genes.

Dawkins proposed that evolution works at the level of genes, and those that happen to possess qualities to adapt its owner/s to their surroundings survive. Genes adapt all kinds of strategies, they not only make their owners behave in their ways, but also form associations with those genes, which help them to propagate themselves more. The genes don't do it with a purpose as we see it, but those which happen to possess self serving abilities (to make more copies of self) survive and evolve.

A species happens to be only a temporary association between a group of these genes, in the vast time line in the history of life, and the gene's strategy to survive extend beyond the physical limits of an organism (like the flu virus making us sneeze). A species share a common genome among itself, and only a fraction of this genome varies among the individual organisms of the species, which gives them individual identities, and these may be called variable genes. The purpose of the gene is served, if it either succeeds in making more copies of itself, or even help identical genes in the other individuals of the same species to propagate themselves. The individuals of species who are more closely related to one, is more likely to a common set of variable genes of the species. In fact, siblings share half of an individuals' variable genes, parents also share half, second degree relatives share only one fourth and third degree relatives share only one eighth. So, if an organism care for its closest relative, that's siblings or kids, and see that they survive, in a survival situation, they make sure that at least half of their genes survive.

So, it's in the genes self interest, that it should see to it that, it makes survives, and makes more copies of itself. But then, why do we see sometimes organisms help each other, cooperate, even sacrifice? We see that, by helping those individuals that share it's genes' copies, they in fact help themselves, or to be more precise, their own genes. In a survival situation, sometimes it may be even beneficial than own survival, to help a related organism, who may be carrying only a portion of it's genes, but has more chances of survival and propagation. So that explains our being good to others. We are not uniformly good to all, but, we love our kith and kin more. We love our spouse, even though it is not related to us, and it's as align to us as any other individual of the species, since it helps our children, who carry half our genes, to survive.

This not only explains why we are good, but also, the selectiveness in it. Another way to help own set of genes to survive, is by preventing alien set from doing so. That explains why we are bad towards others too. The ratio of goodness to badness in our attitude towards others is determined, hence by our degree of relation.

Sea Lions are organisms that live in land and sea, and lay eggs. They tend to their eggs, and help them hatch. There's  population of Sea Lions who live on rough rocks by the sea. When they sit to hatch their eggs, occasionally a few eggs roll out, and they immediately hold them and bring them back under themselves. There's also a population of Sea Lions, who live on smooth rocks, where eggs roll out more and also far. These individuals, when an egg is seen rolling, they break the egg, rather than bring them in to hatch. The difference in behaviour of the two sets of Sea Lion populations is because, in smoother rocks, more eggs roll, and also they roll farther, so, when one spots an egg near it, it's more likely to be egg of another Sea Lion than it's own, so, they break it, there by reducing the competition to it's children, when they come out!

So, selfish gene theory explains us why we are good, why we are more good to our close relatives, those of our own cast, and nation, and also, why we can be as bad as it can, at certain times, towards others. Our genes feed us these instincts, to serve their own purpose! As with theory of evolution, this explains our goodness and evil, in a very simple and elegant manner, without resorting to convoluted stories of sky dwelling creatures and their evil counterparts. 

Sunday, November 3, 2013

When Dreams took Wings

March 3rd, 2013 - the day I can't forget in my life.

That day, I flew a paraglider solo first time, on the third day of my P1 course!!

It all started when I visited Nepal with my family about 3 years back. We went Paragliding in Pokhara. (video here) A pilot carries you in his glider, called tandem flight. I learnt from him that he can navigate the glider to where he wants, soar higher than from where he took off, cover long distances on the glider, even do some acrobatics! That itself was very wonderful and I was talking about it all the time to my friends. Then I started looking if any tandem flights were available in India.

And it turned out that there were a few people offering paragliding training in India, and that, it's actually quite easy! I narrowed in on one school Temple Pilots, who looked good. I later learned that they are the best in the country. I still took one year to summon courage, convince family and get a mate (Lakshman) to join me to the course. Finally landed in Talegaon on March 1st this year, with Lakshman.

I had already watched a few videos and read about paragliding, but on site, on the first day, it looked quite terrifying. We had to do some ground runs carrying the glider. The glider seemed to pull heavily on us, we couldn't control it, we'll fall to our side, the glider will drag us on ground, heads got banged on rocks (of course protected by helmet). To top it, one of the guys who was doing hopping flights had a fall and injured his knees. That night when we sat around, Lakshman said he'll never attempt to fly solo, and he told the Temple Pilots guys so, and that he wanted them to just carry him on a tandem flight to show to his friends back home.


my hopping flight
Second day, again some ground runs, now we seemed to get the hook of controlling the glider, and we could run longer and rather than end up falling, could stop and deflate the glider. We started enjoying the runs, it was beautiful, glider will carry us over small dips on the ground, the legs won't go down into them. Our trainers will give us instructions over radio, to which we now got accustomed, which actually we couldn't listen and obey on the first day, due to the nervousness. Towards the end of the day, they made us fly hopping flights, from a small height, which itself was quite exhilarating.  That night when we sat down, we were really happy, and were looking forward to our last day, when we'll be taken for solo flights, from the top of the hill!

On the final day, I did 4 solo flights. It was beyond words. When I got to top of the hill first time, it was actually terrifying again, the top was just a narrow ridge, with strong winds. We knew from our theory classes that, on the other side of the hill, that's the leeward side of the hill, there are going to be rotors and eddies which is dangerous and no-go for paragliding. It was with heavily beating hearts that we inflated our gliders, assisted by Ankush, our trainer, and then took off. Once in the air, wow, it was amazing, I was flying by myself!!. Ganpath the trainer with radio on ground gave instructions, and I took my turns, reached landing site, did the final flare, and landed on my feet! The flight lasted about one and half minute. But it was wonderful. I had three more flights, and after each flight, was racing back to the top of the 200 feet hill, for a chance at it again.

But the man who enjoyed the most on the day was Lakshman, who on first day said he'll never do solo flight. His first attempt at inflation failed and he fell down, which further scared him. He actually backed out of further attempts but Ankush didnt release him from the glider, quickly inflated it, and sent him off. After landing, he was laughing so much and jumping around, more than all others who did solo.

So, now, we are P1 certified pilots. it doesn't actually mean much. There's so much more to learn, proper launch technics, soaring, thermalling etc. But it all looks exciting and we are determined to carry on ahead with P2, certification course and beyond. It's said that paragliding is initially 90% physical and 10% mental, but later, 10% physical and 90% mental. It already looks to be true, and we are least worried now and quite excited.


Laksman doing solo

Saturday, August 24, 2013

Upload contacts to google as CSV file

You can save your contacts in a simple text file (created with notepad or alternately exported from Excel) and then import from Gmail.
This link contains the directions from Google about how to do this: https://support.google.com/mail/answer/12119#

A few points to note are:

1. The individual fields need not be contained in an apostrophe, which many spreadsheet programs insert. 
2. There should be a header line which names each field.
3. 'Name' field (alternately it can be 'First Name', 'Last Name' etc) and 'E-mail Address' fields are required. It's E-mail no Email as given in google help page.

A sample file may look like:


Name,Mobile Phone,E-mail Address
Mr xxx, 9439843 , xxx@yyy.com
Mr abc, 23489348, abc@xyz.com

In Google, goto Contacts, click on More button on top, select Import, and select CSVfile you saved, and then Import contacts.

Wednesday, July 31, 2013

A great philosophical piece in a book on computer viruses!

The following is from Introduction chapter in 'The little black book on computer viruses' by Mark Ludwig


This is the first in a series of three books about computer
viruses. In these volumes I want to challenge you to think in new
ways about viruses, and break down false concepts and wrong ways
of thinking, and go on from there to discuss the relevance of
computer viruses in today’s world. These books are not a call to a
witch hunt, or manuals for protecting yourself from viruses. On the
contrary, they will teach you how to design viruses, deploy them,
and make them better. All three volumes are full of source code for
viruses, including both new and well known varieties.
It is inevitable that these books will offend some people.
In fact, I hope they do. They need to. I am convinced that computer
viruses are not evil and that programmers have a right to create
them, posses them and experiment with them. That kind of a stand
is going to offend a lot of people, no matter how it is presented.
Even a purely technical treatment of viruses which simply dis-
cussed how to write them and provided some examples would be
offensive. The mere thought of a million well armed hackers out
there is enough to drive some bureaucrats mad. These books go
beyond a technical treatment, though, to defend the idea that viruses
can be useful, interesting, and just plain fun. That is bound to prove
even more offensive. Still, the truth is the truth, and it needs to be
spoken, even if it is offensive. Morals and ethics cannot be deter-
mined by a majority vote, any more than they can be determined
by the barrel of a gun or a loud mouth. Might does not make right.

If you turn out to be one of those people who gets offended
or upset, or if you find yourself violently disagreeing with some-
thing I say, just remember what an athletically minded friend of
mine once told me: “No pain, no gain.” That was in reference to
muscle building, but the principle applies intellectually as well as
physically. If someone only listens to people he agrees with, he will
never grow and he’ll never succeed beyond his little circle of
yes-men. On the other hand, a person who listens to different ideas
at the risk of offense, and who at least considers that he might be
wrong, cannot but gain from it. So if you are offended by something
in this book, please be critical—both of the book and of yourself—
and don’t fall into a rut and let someone else tell you how to think.

From the start I want to stress that I do not advocate
anyone’s going out and infecting an innocent party’s computer
system with a malicious virus designed to destroy valuable data or
bring their system to a halt. That is not only wrong, it is illegal. If
you do that, you could wind up in jail or find yourself being sued
for millions. However this does not mean that it is illegal to create
a computer virus and experiment with it, even though I know some
people wish it was. If you do create a virus, though, be careful with
it. Make sure you know it is working properly or you may wipe out
your own system by accident. And make sure you don’t inadver-
tently release it into the world, or you may find yourself in a legal
jam . . . even if it was just an accident. The guy who loses a year’s
worth of work may not be so convinced that it was an accident. And
soon it may be illegal to infect a computer system (even your own)
with a benign virus which does no harm at all. The key word here
is responsibility. Be responsible. If you do something destructive,
be prepared to take responsibility. The programs included in this
book could be dangerous if improperly used. Treat them with the
respect you would have for a lethal weapon.

This first of three volumes is a technical introduction to the
basics of writing computer viruses. It discusses what a virus is, and
how it does its job, going into the major functional components of
the virus, step by step. Several different types of viruses are
developed from the ground up, giving the reader practical how-to
information for writing viruses. That is also a prerequisite for
decoding and understanding any viruses one may run across in his
day to day computing. Many people think of viruses as sort of a
black art. The purpose of this volume is to bring them out of the
closet and look at them matter-of-factly, to see them for what they
are, technically speaking: computer programs.

The second volume discusses the scientific applications of
computer viruses. There is a whole new field of scientific study
known as artificial life (AL) research which is opening up as a result
of the invention of viruses and related entities. Since computer
viruses are functionally similar to living organisms, biology can
teach us a lot about them, both how they behave and how to make
them better. However computer viruses also have the potential to
teach us something about living organisms. We can create and
control computer viruses in a way that we cannot yet control living
organisms. This allows us to look at life abstractly to learn about
what it really is. We may even reflect on such great questions as the
beginning and subsequent evolution of life.
The third volume of this series discusses military applica-
tions for computer viruses. It is well known that computer viruses
can be extremely destructive, and that they can be deployed with
minimal risk. Military organizations throughout the world know
that too, and consider the possibility of viral attack both a very real
threat and a very real offensive option. Some high level officials in
various countries already believe their computers have been at-
tacked for political reasons. So the third volume will probe military
strategies and real-life attacks, and dig into the development of viral
weapon systems, defeating anti-viral defenses, etc.
You might be wondering at this point why you should
spend time studying these volumes. After all, computer viruses
apparently have no commercial value apart from their military
applications. Learning how to write them may not make you more
employable, or give you new techniques to incorporate into pro-
grams. So why waste time with them, unless you need them to sow
chaos among your enemies? Let me try to answer that: Ever since
computers were invented in the 1940’s, there has been a brother-
hood of people dedicated to exploring the limitless possibilities of
these magnificent machines. This brotherhood has included famous
mathematicians and scientists, as well as thousands of unnamed
hobbyists who built their own computers, and programmers who
love to dig into the heart of their machines. As long as computers
have been around, men have dreamed of intelligent machines which
would reason, and act without being told step by step just what to
do. For many years this was purely science fiction. However, the
very thought of this possibility drove some to attempt to make it a
reality. Thus “artificial intelligence” was born. Yet AI applications
are often driven by commercial interests, and tend to be colored by
that fact. Typical results are knowledge bases and the like—useful,
sometimes exciting, but also geared toward putting the machine to
use in a specific way, rather than to exploring it on its own terms.

The computer virus is a radical new approach to this idea
of “living machines.” Rather than trying to design something which
poorly mimics highly complex human behavior, one starts by trying
to copy the simplest of living organisms. Simple one-celled organ-
isms don’t do very much. The most primitive organisms draw
nutrients from the sea in the form of inorganic chemicals, and take
energy from the sun, and their only goal is apparently to survive
and to reproduce. They aren’t very intelligent, and it would be tough
to argue about their metaphysical aspects like “soul.” Yet they do
what they were programmed to do, and they do it very effectively.
If we were to try to mimic such organisms by building a machine—
a little robot—which went around collecting raw materials and
putting them together to make another little robot, we would have
a very difficult task on our hands. On the other hand, think of a
whole new universe—not this physical world, but an electronic one,
which exists inside of a computer. Here is the virus’ world. Here it
can “live” in a sense not too different from that of primitive
biological life. The computer virus has the same goal as a living
organism—to survive and to reproduce. It has environmental ob-
stacles to overcome, which could “kill” it and render it inoperative.
And once it is released, it seems to have a mind of its own. It runs
off in its electronic world doing what it was programmed to do. In
this sense it is very much alive.

There is no doubt that the beginning of life was an impor-
tant milestone in the history of the earth. However, if one tries to
consider it from the viewpoint of inanimate matter, it is difficult to
imagine life as being much more than a nuisance. We usually
assume that life is good and that it deserves to be protected.
However, one cannot take a step further back and see life as
somehow beneficial to the inanimate world. If we consider only the
atoms of the universe, what difference does it make if the tempera-
ture is seventy degrees farenheit or twenty million? What difference
would it make if the earth were covered with radioactive materials?
None at all. Whenever we talk about the environment and ecology,
we always assume that life is good and that it should be nurtured
and preserved. Living organisms universally use the inanimate
world with little concern for it, from the smallest cell which freely
gathers the nutrients it needs and pollutes the water it swims in,
right up to the man who crushes up rocks to refine the metals out
of them and build airplanes. Living organisms use the material
world as they see fit. Even when people get upset about something
like strip mining, or an oil spill, their point of reference is not that
of inanimate nature. It is an entirely selfish concept (with respect
to life) that motivates them. The mining mars the beauty of the
landscape—a beauty which is in the eye of the (living) beholder—
and it makes it uninhabitable. If one did not place a special
emphasis on life, one could just as well promote strip mining as an
attempt to return the earth to its pre-biotic state!

I say all of this not because I have a bone to pick with
ecologists. Rather I want to apply the same reasoning to the world
of computer viruses. As long as one uses only financial criteria to
evaluate the worth of a computer program, viruses can only be seen
as a menace. What do they do besides damage valuable programs
and data? They are ruthless in attempting to gain access to the
computer system resources, and often the more ruthless they are,
the more successful. Yet how does that differ from biological life?
If a clump of moss can attack a rock to get some sunshine and grow,
it will do so ruthlessly. We call that beautiful. So how different is
that from a computer virus attaching itself to a program? If all one
is concerned about is the preservation of the inanimate objects
(which are ordinary programs) in this electronic world, then of
course viruses are a nuisance.

But maybe there is something deeper here. That all depends
on what is most important to you, though. It seems that modern
culture has degenerated to the point where most men have no higher
goals in life than to seek their own personal peace and prosperity.
By personal peace, I do not mean freedom from war, but a freedom
to think and believe whatever you want without ever being chal-
lenged in it. More bluntly, the freedom to live in a fantasy world of
your own making. By prosperity, I mean simply an ever increasing
abundance of material possessions. Karl Marx looked at all of
mankind and said that the motivating force behind every man is his
economic well being. The result, he said, is that all of history can
be interpreted in terms of class struggles—people fighting for
economic control. Even though many in our government decry
Marx as the father of communism, our nation is trying to squeeze
into the straight jacket he has laid for us. That is why two of George
Bush’s most important campaign promises were “four more years
of prosperity” and “no new taxes.” People vote their wallets, even
when they know the politicians are lying through the teeth.

In a society with such values, the computer becomes
merely a resource which people use to harness an abundance of
information and manipulate it to their advantage. If that is all there
is to computers, then computer viruses are a nuisance, and they
should be eliminated. Surely there must be some nobler purpose
for mankind than to make money, though, even though that may be
necessary. Marx may not think so. The government may not think
so. And a lot of loud-mouthed people may not think so. Yet great
men from every age and every nation testify to the truth that man
does have a higher purpose. Should we not be as Socrates, who
considered himself ignorant, and who sought Truth and Wisdom,
and valued them more highly than silver and gold? And if so, the
question that really matters is not how computers can make us
wealthy or give us power over others, but how they might make us
wise. What can we learn about ourselves? about our world? and,
yes, maybe even about God? Once we focus on that, computer
viruses become very interesting. Might we not understand life a
little better if we can create something similar, and study it, and try
to understand it? And if we understand life better, will we not
understand our lives, and our world better as well?

A word of caution first: Centuries ago, our nation was
established on philosophical principles of good government, which
were embodied in the Declaration of Independence and the Consti-
tution. As personal peace and prosperity have become more impor-
tant than principles of good government, the principles have been
manipulated and redefined to suit the whims of those who are in
power. Government has become less and less sensitive to civil
rights, while it has become easy for various political and financial
interests to manipulate our leaders to their advantage.

Since people have largely ceased to challenge each other
in what they believe, accepting instead the idea that whatever you
want to believe is OK, the government can no longer get people to
obey the law because everyone believes in a certain set of principles
upon which the law is founded. Thus, government must coerce
people into obeying it with increasingly harsh penalties for disobe-
dience—penalties which often fly in the face of long established
civil rights. Furthermore, the government must restrict the average
man’s ability to seek recourse. For example, it is very common for
the government to trample all over long standing constitutional
rights when enforcing the tax code. The IRS routinely forces
hundreds of thousands of people to testify against themselves. It
routinely puts the burden of proof on the accused, seizes his assets
without trial, etc., etc. The bottom line is that it is not expedient for
the government to collect money from its citizens if it has to prove
their tax documents wrong. The whole system would break down
in a massive overload. Economically speaking, it is just better to
put the burden of proof on the citizen, Bill of Rights or no.

Likewise, to challenge the government on a question of
rights is practically impossible, unless your case happens to serve
the purposes of some powerful special interest group. In a standard
courtroom, one often cannot even bring up the subject of constitu-
tional rights. The only question to be argued is whether or not some
particular law was broken. To appeal to the Supreme Court will cost
millions, if the politically motivated justices will even condescend
to hear the case. So the government becomes practically all-pow-
erful, God walking on earth, to the common man. One man seems
to have little recourse but to blindly obey those in power.

When we start talking about computer viruses, we’re tread-
ing on some ground that certain people want to post a “No Tres-
passing” sign on. The Congress of the United States has considered
a “Computer Virus Eradication Act” which would make it a felony
to write a virus, or for two willing parties to exchange one. Never
mind that the Constitution guarantees freedom of speech and
freedom of the press. Never mind that it guarantees the citizens the
right to bear military arms (and viruses might be so classified).
While that law has not passed as of this writing, it may by the time
you read this book. If so, I will say without hesitation that it is a
miserable tyranny, but one that we can do little about . . . for now.

Some of our leaders may argue that many people are not
capable of handling the responsibility of power that comes with
understanding computer viruses, just as they argue that people are
not able to handle the power of owning assault rifles or machine
guns. Perhaps some cannot. But I wonder, are our leaders any better
able to handle the much more dangerous weapons of law and
limitless might? Obviously they think so, since they are busy trying
to centralize all power into their own hands. I disagree. If those in
government can handle power, then so can the individual. If the
individual cannot, then neither can his representatives, and our end
is either tyranny or chaos anyhow. So there is no harm in attempting
to restore some small power to the individual.
But remember: truth seekers and wise men have been
persecuted by powerful idiots in every age. Although computer
viruses may be very interesting and worthwhile, those who take an
interest in them may face some serious challenges from base men.
So be careful.

Now join with me and take the attitude of early scientists.
These explorers wanted to understand how the world worked—and
whether it could be turned to a profit mattered little. They were
trying to become wiser in what’s really important by understanding
the world a little better. After all, what value could there be in
building a telescope so you could see the moons around Jupiter?
Galileo must have seen something in it, and it must have meant
enough to him to stand up to the ruling authorities of his day and
do it, and talk about it, and encourage others to do it. And to land
in prison for it. Today some people are glad he did.
So why not take the same attitude when it comes to creating
life on a computer? One has to wonder where it might lead. Could
there be a whole new world of electronic life forms possible, of
which computer viruses are only the most rudimentary sort? Per-
haps they are the electronic analog of the simplest one-celled
creatures, which were only the tiny beginning of life on earth. What
would be the electronic equivalent of a flower, or a dog? Where
could it lead? The possibilities could be as exciting as the idea of a
man actually standing on the moon would have been to Galileo. We
just have no idea.
There is something in certain men that simply drives them
to explore the unknown. When standing at the edge of a vast ocean
upon which no ship has ever sailed, it is difficult not to wonder what
lies beyond the horizon just because the rulers of the day tell you
you’re going to fall of the edge of the world (or they’re going to
push you off) if you try to find out. Perhaps they are right. Perhaps
there is nothing of value out there. Yet other great explorers down
through the ages have explored other oceans and succeeded. And
one thing is for sure: we’ll never know if someone doesn’t look. So
I would like to invite you to climb aboard this little raft that I have
built and go exploring. . . .