May 21, 2006

Installing Sun Java on Ubuntu

Drew Stephens @ 7:12 pm — Tags: , , ,

I installed Azureus on my Ubuntu machine recently and found it to absolutely peg the CPU when downloading more than a few torrents at once. I know that Bittorrent is a pretty CPU intensive protocol, but I had been running similar numbers of torrents on the same machine using bittornado with much less ado. By default, Ubuntu installs the GCJ Java virtual machine, which is a perfectly serviceable JVM, but I suspected it wasn’t as good as Sun’s own. I’ll shall not decree that Sun’s JVM is better than GCJ, as I didn’t actually run any tests, but Azureus runs faster now that I’m using the Sun machine. Onward.

Overall this is a pretty simple install. First, because of how Sun’s JVM is licensed, you need to manually download it from the Sun site. If you plan on compiling Java code, get the Java Development Kit (JDK); if you don’t write software, you can just get the Java Runtime Environment (JRE). Either way, make sure you get the vanilla package, not the RPM (RedHat package).

Once you have that, you need to install java-package using apt-get. You will first need to change two lines in your /etc/apt/sources.list file, adding universe and multiverse as is shown below:

deb http://us.archive.ubuntu.com/ubuntu/ dapper main restricted universe multiverse
deb-src http://us.archive.ubuntu.com/ubuntu/ dapper main restricted universe multiverse

Open a terminal and type this in, answering “yes” to any questions the program asks:

sudo apt-get install java-package

Now, you just need to make a .deb out of Sun’s Java package that you grabbed. In the same terminal, change to the directory where said package resides and run the following, once again choosing happy answers like ‘y’ and ‘yes’ when you are presented with quesions:

chmod +x *.bin; fakeroot make-jpkg *.bin; sudo dpkg -i sun-j2sdk*.deb

Easy as that. To make this the default JVM simply run the following command:

sudo update-java-alternatives --config java

May 6, 2006

Obfuscated code

Drew Stephens @ 12:27 pm — Tags: ,

I’m doing a project on MD5 collisions for my parallel computing class and, like all cryptography, the code involves a lot of hex numbers (in standard notation, 0xf00d, 0xbeef, etc.) which naturaly makes parts of the code difficult to read. That’s simply the nature of the algorithm. Some programmers (often just mathematicians) insist on making the code even more illedgible with things like this:

while (counter < (1 << 9))

The bigger problem is that when I see something like that I’m confused; I am both impressed by their cleverness (that loops while counter is less than 512) but also annoyed by their needless obfuscation. I guess one could argue that a left shift is more ledgible, because if it were a number larger than 10 or so, people wouldn’t know the significance. Who really knows of the top of their head that 262144 is 2^18? So, in the end, it’s not necessarily just obfuscation but really, most programmers will recognize at least up to 2^10 and those who know the internets should know 2^16 as well.

May 1, 2006

Random number generators

Drew Stephens @ 6:25 pm — Tags: ,

As I read more about cryptography (I’m currently making my way through the great tome, Applied Cryptography) I’ve been thinking more about random number generators. Whenever you read about cryptography or how they build slot machines (Kevin Mitnick covers this in The Art of Intrusion) there is talk of how bad computer random number generators are, particularly the standard functions that are part of Java, libc or .NET. Even if you take the time to seed them, the pseudo-randomness is of quite low quality. I just found an article on some random number generators you can implement yourself. Cool.

Powered by WordPress