Introuducing ScribeSense

Posted in Code

Some of you may know that I’m making a documentary this summer, but what very few people knew was that the documentary is just another excuse for me to be incredibly geeky. Ladies and gentlemen, boys and girls, please give a warm welcome to:

ScribeSense - Video transcription without the trauma

Basically, ScribeSense is a tool for annotating (transcribing) video without resorting to burning lots of DVDs. You’ll probably only ever find this useful if you’re doing some kind of film production, but if you are I hope it becomes an invaluable friend.

I generally end this sort of thing with a snippet, and I’m not gonna let y’all down today:

function cuepoint() {
	if (this.inputbox.text.length>1) {
		var itemlabel:String = "[" + sec2tc(this.secbox.text) + "]\t"+ snip_txt(this.inputbox.text);
		if (edit_item_index.text.length>0) {
			var editIndex = Number(edit_item_index.text);
			logDP.replaceItemAt({label:itemlabel,timestamp:Number(this.secbox.text), data:this.inputbox.text},editIndex);
			edit_item_index.text = "";
		} else {
			logDP.addItem({label:itemlabel,timestamp:Number(this.secbox.text), data:this.inputbox.text});
		}
		logDP.sortOn("timestamp");
	}
	this.inputbox.text = "";
	this.secbox.text = timecode();
	this.tcbox.text = sec2tc(timecode());
}

The whole thing is a veritable mixing pot of actionscript, PHP and javascript with lashings of XML holding it all together. Producing it made me insanely happy.

Feedback would be appreciated (if you have any) through the usual channels.

Tom x

No Comments »

MD5 in PHP works exactly as it should (don’t believe the hype!)

Posted in Code

Hey guys,

I’m afraid today I have to confess to an almighty amount of stupidity, but first - please allow me to set the record straight so that nobody ever makes that mistake again:

The PHP MD5 function produces the same hashes as any other MD5 function written in any other language ever devised.

Please don’t pay any heed whatsoever to the whisperings that abound the wonderful interweb. Hmmm… Maybe ‘abound’ isn’t the right word, which is exactly what should have sent the rumour-alarm clanging away in my head. Truth is, there are a small spattering of references to this problem, but often people (like me) work out that it was a problem with their own code that they attributed to the ‘encoding problem’ because it’s easier to ‘blame their tools‘.

As was pointed out to me:

md5 always takes the argument as a bit vector rather than a string of letters, i.e. no encoding matters. If your script is written in ISO-8559-15 and you passed an embedded string literal to md5(), the result is the hash of a ISO-8859-15 string

Y’know what? It’s true! When I did a bit more debugging I found that I was inserting invisible whitespace into the string I tried hashing. Whitespace is as visible as any other character to the MD5 function - the hash of ‘ hashtext’ (notice the leading space) will therefore be different to the hash of ‘hashtext’. Nothing to do with utf7 or utf8!

And guess what? It’s not just me… On experts exchange1 I found a user with a similar problem in Java. He later explains that in his case a string wasn’t being lowecased prior to hashing:

Hello. Have got access to the php code now and can see that the php programmer did not actually follow the specification (did not make all chars to lowercase bfore md5…) Sorry to have bothereed u with this, was extremely painfull to sort out the bug when I could not see the php code.

But this sort of response is never publicised in the same way. These answers, these non-problems, are always buried as apologetic admissions of bad development practice. I want to put an end to this, and by publishing this post I hope to nip this slowly spreading rumour in the bud.

Go forth and spread the good news - The PHP MD5 is not dead. Long live (urm) the PHP MD5 function!

Tom x


Footnotes:

  1. See here to access without a login []

7 Comments »

How not to walk away from a project…

Posted in Code

OK - earlier today I said that I was going to stop messing about with ASCII and Brainfuck…

Well, I lied.

Ladies and gentlemen, boys and girls, please put your hands together for the amazing

Brainfuck ASCII art message concealer!

“What does it do though Tom?” - Put simply, it hides text inside an image of your choice. To do this, does the following:

  • First it creates the Brainfuck script for the text you supply
  • Next it creates an ASCII version of the picture (default or user supplied)
  • Third is replaces the non-brainfuck ASCII characters with the brainfuck script, in order, and with respect to the brightness of each ‘pixel’.

Still confused? Don’t worry - Brainfuck is just a really minimalist programming language. Here it is on Wikipedia and in the 99 Bottles repository.

I’d like to thank Jonathan Ford for writing the class on which the ASCII picture generator is based.

Source files:

And, because I’m feeling reckless, a snippet:

  private function conceal ($char) {
    if (($this->pointer < count($this->msgarray))&&(in_array($char, $this->matches[$this->msgarray[$this->pointer]]))) {
      $char = $this->msgarray[$this->pointer];
      $this->pointer++;
    }
    return $char;
  }

How’d you like them apples? I’m tired now, and am going to bed.

You’ve been wonderful,

Tom x

No Comments »

2 Shiny Toys To Play With

Posted in Code

As promised yesterday, I have some exciting surprises for you all. It’s not quite as finished as I’d like, but I need to carry on with my life. Shame…

Anyway, I’d like to introduce you all to a couple of friendly mini-tools that I wrote:

Brainfuck text encoder

Brainfuck is (before I’m yelled at) is a legitimate (though slightly esoteric) programming language. It has only 8 functions and is consequently a bit tricky to use in real life.

This app generates a BF script that will (upon execution) output the text of your choice.

ASCII art darkness comparison

This is entirely different. It allows you to compare an ASCII character of your choice with a customizable palette of other ASCII characters. This is almost entirely pointless on it’s own, but may be of some use if you were building, oh I don’t know, an ASCII art generator?

So there you go. Next time I’m bored I’ll finish building what I started - The brainfuck text ascii art concealer! Mwahahah! Watch this space,

Tom

1 Comment »