Sunday, April 13, 2008

Winners vs Losers

This is a thought from months back. I saw somewhere the quote "Winners don't do different things. They just do things differently". If winners are people who do the same things as losers but in a different way, it would turn out that losers are people who do the same things as winners but in a different way. Then what is the difference between them?

Well, as the quote itself is rather stupid (how can you define a winner? A person who is happy or a person who appears to be happy or a person who others feel ought to be happy?), the thought was not exactly revolutionary and there was no need to go further. Still, I felt good.

One Subtly Illogical Argument

Once when I was 10 or 11 I looked at some pictures drawn by children in a Newspaper and commented tactlessly to my brother that many hardly esembled what they were supposed to resemble. He asked if I could draw even half as good. Thinking about my own "horrifyingly original" creations, I answered truthfully "no". "Then don't make fun of them", he said. "You have no right to criticize someone if you can't do better"

I was confused. I sensed there was something wrong with the logic but couldn't tell exactly what it was. Now I would have replied "Well, you don't have to be a master cook to taste something, right?" The fallacy of the logic here needs no pointing out.

What I want to emphasize is not of course that I have a damn good right to comment on any food I come across (which, by the way, I do have). It is that many "logical" arguments when seen in a different light reveal themselves to be surprisingly hollow.

"Mature" intellects may think that this no-right-to-tell-what-you-think specious reasoning cannot be used to confuse them. It is, in most part, a mistaken smugness and that is why being "mature" is not always a desirable thing. Thinking like a child is an art(lessness) we should all practice.

Anyway, when speaking about the God hypothesis, one argument I repeatedly hear is: "If there is no God, how can you explain the universe? How do you account for the planets, the laws, the mathematics?". See the sophistry? The argument is exactly the same. If you don't have a better hypothesis (If you can't cook better .... ) you have no right to criticize the current one (.... eat quietly even if you would love to throw up). Now see? I wonder what would the leading mathematicians have replied if someone, after having presented a fallacious proof for the Fermat's last theorem and having been rejected, had said: "You don't have a valid proof yet. So you have no right to reject my proof." Fortunately, I can wonder as such an incident has not (as far as I can tell), occurred.

Incidentally, no one who presented this argument to me were deliberately trying to mislead. They themselves were "blinded by logic" as it were. I am very curious to know the real origin of this line of reasoning.

Again incidentally, there are hypotheses that are at least as valid as the God hypotheses explainining the Life, the Universe and Everything (even the hilarious hypotheses expressed in the The Hitchhiker's Guide to the Galaxy are more coherent). But the whole point of this sermon is that lack of alternative theories doesn't constitute any kind of proof.

Thursday, April 3, 2008

A Random Password Generator

A good password should be as random as possible, not just pseudo-random. Hence password generator programs shouldn't depend on the library functions like rand() because they generate reproducible "random" numbers whose "randomness" depends solely on the seed.

Here is a simple password generator in Perl which uses random bits from /dev/random to generate as good a password as can be made on a Unix machine. The password length can be specified as an optional argument. By default, it generates a password of length 10.


#!/usr/bin/perl -w

# (C) Minus i 2008
# Permission is granted to copy, modify and/or redistribute this under the
# terms of GNU General Public Licence version 3, or later.

use bignum;   # for arithmetic that may transgress
              # from the integer field

use Config;   # to know the integer sizes in the system

$len=$ARGV[0]>0?int $ARGV[0]:10; # by default, generate a password of length 10

open R, "/dev/random", or die "couldn't open: $!";

# password contains characters from this array
@CHR=('a'..'z','A'..'Z',0..9,' ',
qw(~ ! @ $ % ^ & * - _ = + \ | ; : < > . / ? ));


$intsize=$Config{ivsize};
$maxint=(1<<8*$intsize)-1;># The idea is simple. To generate a character, we read $intsize bytes
# from the random file and use it to get a random number in the range of
# 0 and $#CHR. With this, we just index the array.

read R, $buf,$intsize*$len;


$pw="";

# The Unpack function is used to get $len integers of $intsize bytes each
# from the string $buf
map {$pw.=$CHR[int (@CHR * ($_/(1+$maxint)))]} unpack("I$intsize"x$len,$buf);

# Work over, print the password
print"$pw\n";




Caution: Since the program uses /dev/random, in GNU/Linux systems it may block until the system has gathered enough entropy. You can use /dev/urandom to generate less random passwords faster, but I would advise against it. While you are at it, generate highly secure passwords.