a sign-up-form lesson

September 7, 2009 systems 1 comment

I came across mail.yeah.net, from a Chinese Internet provider, and thought I’d try out their free email service, and see how that would work out.

The sign up form was full of Chinese characters, naturally, still I could type in my name, fill in the password, date of birth etc. But after about 10 fields or so, I got to this section:

Screenshot from sign up form

Screenshot from the yeah.net sign up form

Now I was kind of stuck. I went to Google / Translate and and pasted in the label, and clicked the “Translate” button:

Screen shot from Google Translate

Screen shot from Google Translate

Please type in the characters above! — a CAPTCHA field — of course! Now I was definitely stuck, and gave up! (I don’t know Chinese characters, nor do I know how to produce them with my keyboard)

I’ve been putting CAPTCHAs on some websites myself, to keep out spam and abuse; see

My friends tell me often that they don’t like it when they have to tackle those CAPTCHAs (this is why I thought of the CAPTCHA for the stephansmap sign up form: it is supposed to entertain, as far as my entertainment talents go in terms of computer graphics.) But it definitely stops the spammers.

So with yeah.net I got to see this all from a different perspective.

the critical mass of the cbc

July 31, 2009 cbc 1 comment

Well tonight, the Canadian Broadcasting Corporation, the “CBC”, is reporting

An estimated 1,000 bicycle-riding members of Critical Mass again disrupted Friday’s rush hour traffic in Vancouver in the latest of the group’s planned monthly protests to promote urban bike use.

See http://www.cbc.ca/canada/british-columbia/story/2009/07/31/bc-critical-mass-bike-ride-vancouver-mayor.html

Instead of sending the CBC a letter to point out the inaccuracy, I thought I’d write it up here.

The unusual, the special nature, what you cannot miss about Critical Mass rides, and what is really quite easy to find out, and what makes it different from many other similar happenings, is that:

  • they are not a group with membership
  • they are not organized
  • they are not a protest (movement)
  • they are not demonstrations.

They are just rides that happen in the evening of the last Friday of each month. There is no agreed upon route. There is no leader. There are no “members of Critical Mass”.

And if a journalist writes about Critical Mass and doesn’t find that out then they haven’t done their homework. It’s really not that hard!

Here’s what wikipedia says about Critical Mass Rides.

Here’s an informal wiki about critical mass rides.

the newspaper deliveryman and the policeman

July 29, 2009 bc No comments

Here’s a clever comment from Rex Mundi on the story of a newspaper deliveryman being viciously attacked by a number of drunk policemen. The policemen were charged, and one of them “has been given a conditional sentence without jail time after pleading guilty” today. (The others’ trials are not complete yet)

His comment is:

So does this mean that off-duty newspaper deliverymen may anticipate no jail time if they get drunk and assault an off-duty police officer?

See http://www.cbc.ca/canada/british-columbia/story/2009/07/29/bc-west-vancouver-policeman-gillan-assault-sentence.html

cryptography: a note on cipher block chaining

July 25, 2009 programming No comments

I’ve been looking into encryption methods recently, and came across this little surprise about cipher block chaining, or CBC, as it is used for block ciphers.

Block ciphers only encrypt messages of a fixed length, which depends on the cipher. To encrypt longer messages one breaks them up into blocks with the block cipher’s length and then individually encrypts these blocks. The receiver decrypts all the encrypted blocks and pastes the original message together. So for example, if your message is 2 kilobytes long (one ordinary page of writing), and the block cipher length is 32 bytes, then 2 kilobytes / 32 bytes = 2 * 1024 / 32 = 64 blocks of 32 bytes each will be encrypted. (Padding may or may not be necessary)

The idea of cipher block chaining is that if such a long message contains identical blocks, or two messages contain identical blocks, then you can tell that from the encrypted parts: they will be the same. Whoever has access to the encrypted message, and if they know the block cipher employed, then they can extract these blocks. While they cannot decrypt the individual blocks, they can compare them. Such is the world of cryptography that there are cases where it should be made difficult to tell that one message contains parts of a different message, or repeats itself.

Cypher Block Chaining

One solution, and the most commonly used “mode of operation” for a block cipher (see 1 , 2 , 3 ) is called Cipher Block Chaining. The idea is to introduce an additional block, called “initial vector”. This block is XOR-ed with the first block to be encrypted. The result is encrypted, and yields the first encrypted block to be sent. This block is however also XOR-ed with the next block to be encrypted. The result is encrypted, and yields the second encrypted block to be sent, and so on. Let’s generalize, and describe more accurately:

Suppose our numbering is such that the first block has number 1 (not 0 as is common).

  • Let P(i) be the i-th block of the plain text message.
  • Let E(X) be the result of encrypting the (plain text) block X.
  • Let D(Y) be the result of decrypting the (encrypted) block Y.
  • Let C(i) be the i-th encrypted (cipher) block.

Then encryption with Cipher Block Chaining can be formalized as:

C(0) := IV, the initial vector
C(i) := E( P(i) XOR C(i-1))

If the receiver knows the initial vector as well as the block cipher’s encryption key they can completely decrypt the message. Decryption is formalized like this:

C(0) := IV, the initial vector
P(i) := D( C(i) ) XOR C(i-1)

Decrypting with a Different Initial Vector

Finally I can point out what surprised me: it is that when decrypting, the blocks P(2), P(3), P(4), and so on do not depend on the initial vector IV that was used for encryption! Only P(1), the first decrypted block, depends on IV, while the other parts of the decrypted message will be the same regardless of IV.

In this way, the contribution of the initial vector is very different from the encryption key! And it is rather nice to see that it need not be any stronger, since it provides the function it is designed for: to hide the information about identical blocks.

And so, if the message is prepended by the the encrypter with some arbitrary initial block, the receiver does not need to know the initial vector used for encryption. After decrypting with some arbitrarily chosen initial vector (all 0’s, for example) they can just throw away the first block; the remaining blocks will represent the encrypted message.

Sample Code with AES and openssl

Here is some rather simple code to illustrate the effect. It is based on one of the Rijndael block ciphers, AES-256 (see Advanced Encryption Standard), and the openssl libary. The openssl options for  enc, “symmetric cipher routines”, are available through man enc

echo "The symmetric cipher commands allow data to be encrypted or decrypted using various block and stream ciphers" > msg.in
# Encrypt msg.in with some key and an initial vector
openssl enc -aes-256-cbc -K 1234567890123456 -iv 1234567890123456 -in msg.in -out msg.crypt
echo Decrypt with both the right key and the right iv
openssl enc -d -aes-256-cbc -K 1234567890123456 -iv 1234567890123456 -in msg.crypt
echo Decrypt with the right key but a different iv
# Pipe into 'od -cx' because there will likely be non-displayable characters. msg.crypt is a properly binary file
openssl enc -d -aes-256-cbc -K 1234567890123456 -iv ABCDEF1234560FED -in msg.crypt | od -cx
echo Compare with the output with the right key and the right iv
openssl enc -d -aes-256-cbc -K 1234567890123456 -iv 1234567890123456 -in msg.crypt | od -cx

When executed in a UNIX shell, and all the required programs are available, the output is:

Decrypt with both the right key and the right iv
The symmetric cipher commands allow data to be encrypted or decrypted using various block and stream ciphers
Decrypt with the right key but a different iv
0000000 355 221 334   J 327   =   V 326   e   t   r   i   c       c   i
        91ed 4adc 3dd7 d656 7465 6972 2063 6963
0000020   p   h   e   r       c   o   m   m   a   n   d   s       a   l
        6870 7265 6320 6d6f 616d 646e 2073 6c61
0000040   l   o   w       d   a   t   a       t   o       b   e       e
        6f6c 2077 6164 6174 7420 206f 6562 6520
0000060   n   c   r   y   p   t   e   d       o   r       d   e   c   r
        636e 7972 7470 6465 6f20 2072 6564 7263
0000100   y   p   t   e   d       u   s   i   n   g       v   a   r   i
        7079 6574 2064 7375 6e69 2067 6176 6972
0000120   o   u   s       b   l   o   c   k       a   n   d       s   t
        756f 2073 6c62 636f 206b 6e61 2064 7473
0000140   r   e   a   m       c   i   p   h   e   r   s  n  
        6572 6d61 6320 7069 6568 7372 000a
0000155
Compare with the output with the right key and the right iv
0000000   T   h   e       s   y   m   m   e   t   r   i   c       c   i
        6854 2065 7973 6d6d 7465 6972 2063 6963
0000020   p   h   e   r       c   o   m   m   a   n   d   s       a   l
        6870 7265 6320 6d6f 616d 646e 2073 6c61
0000040   l   o   w       d   a   t   a       t   o       b   e       e
        6f6c 2077 6164 6174 7420 206f 6562 6520
0000060   n   c   r   y   p   t   e   d       o   r       d   e   c   r
        636e 7972 7470 6465 6f20 2072 6564 7263
0000100   y   p   t   e   d       u   s   i   n   g       v   a   r   i
        7079 6574 2064 7375 6e69 2067 6176 6972
0000120   o   u   s       b   l   o   c   k       a   n   d       s   t
        756f 2073 6c62 636f 206b 6e61 2064 7473
0000140   r   e   a   m       c   i   p   h   e   r   s  n  
        6572 6d61 6320 7069 6568 7372 000a
0000155

As you can see only the first few bytes differ when using the "wrong initial vector".

Just for future reference, here is my system information when running the above code:

$ uname -a
Linux myosin 2.6.24-19-generic #1 SMP Wed Aug 20 22:56:21 UTC 2008 i686 GNU/Linux
$ bash --version
GNU bash, version 3.2.39(1)-release (i486-pc-linux-gnu)
Copyright (C) 2007 Free Software Foundation, Inc.
$ openssl version
OpenSSL 0.9.8g 19 Oct 2007

slashdot down

May 7, 2009 internet No comments

Website administrators fear the slashdot effect (“slashdotting” / “being slashdotted”) — now slashdot.org, “News for nerds. Stuff that matters.”,  is down itself. Here is a screen shot:

Screenshot

Unclear what “Guru Meditation” refers to, but in case you’re wondering, the Varnish link generated by the slashdot web server goes to http://www.varnish-cache.org. Which takes you to http://varnish.projects.linpro.no, which says,

Welcome to the Varnish project
Varnish is a state-of-the-art, high-performance HTTP accelerator

(The slashdot site was working again an hour later)

democratic alternative action now

May 5, 2009 systems No comments

Over here in British Columbia (“B.C.” – also known as “Bring Cash”), it’s election time. (I can’t vote for lack of citizenship, but that is another story.) This time, like last time, there is also a referendum on “Electoral Reform”, to switch to the Single Transferable Vote system (oh boy, they even have a video).

On the weekend I remembered a few ideas I had some years ago about alternatives to the ordinary democratic arrangement. I could recall two but I knew there were three; it took a visit to the Wise Hall to recover the third one: it was a friend’s favourite from when I passed it by her at the time.

None of these are likely to work as such; I think it’s nice to ponder though. Here they are, enjoy:

1. “Copy and Paste”

Instead of maintaining a parliament for your city, province or country, just copy the laws some other parliament comes up with and make them your own. They pass a new law, it becomes yours too. They remove one, its gone for you. Why would you think you can do better than they? Save the time and effort! Usually no one is happy with their parliament anyway.

2. “Everyone is a Minister”

Instead of maintaining a government, divide up all its functions among the constituents. There will be a long list of small areas and responsibilities. Assign each of these areas and responsibilities to one person only: no arguments, they have all the say in their area. If you see something that’s wrong there’s exactly one person to complain to.

Ordinarily, ministers are appointed because of who they know, instead of what they know. After ten years every one of the mini-ministers will be an expert in their field, and do a much better job.

3. “The Less Power, the More Votes”

Usually each person gets one vote. However, some people already have a lot of power over other people’s lives. For example, a store manager has eight hours a day to have things their way. CEO’s of big companies may have thousands of people follow their lead.

At election time, this is reversed. For each person, add up the number of hours times the number of people, for an election period, that they control those other people. If a person controls people that control other people, add the hours from the middle person to the one at the top. The more hours a person is assigned, the less their vote counts.

nice one

April 30, 2009 systems No comments

Listen to how this one flows:

Further, it should be noted that since relativistic quantum theories (such as quantum field theory) can always be expressed in terms of a local Lagrangian density, it follows that probability mass in such theories always flows locally through configuration space, and therefore that a classical configuration of the system’s (field) variables can still be made to evolve locally in a way that simply tracks the flow of the conserved probability current in configuration space.

Source: http://en.wikipedia.org/wiki/Bohm_interpretation

74 words. I think the climax is at “simply”.

Here’s the vocabulary (48 words), sorted alphabetically, with repetitions:

  • a
  • a
  • a
  • always
  • always
  • and
  • as
  • be
  • be
  • be
  • can
  • can
  • classical
  • configuration
  • configuration
  • configuration
  • conserved
  • current
  • density
  • evolve
  • expressed
  • field
  • field
  • flow
  • flows
  • follows
  • further
  • in
  • in
  • in
  • in
  • it
  • it
  • Lagrangian
  • local
  • locally
  • locally
  • made
  • mass
  • noted
  • of
  • of
  • of
  • probability
  • probability
  • quantum
  • quantum
  • relativistic
  • should
  • simply
  • since
  • space
  • space
  • still
  • such
  • such
  • system’s
  • terms
  • that
  • that
  • that
  • that
  • the
  • the
  • the
  • theories
  • theories
  • theory
  • therefore
  • through
  • to
  • tracks
  • variables
  • way

the “free will theorem”: a gedanken experiment

April 25, 2009 systems No comments

The Free Will Theorem, published in 2006 by John H. Conway and Simon Kochen, says in rough terms, that if we (as humans) have free will then so do elementary particles. As you would ordinarily take it for granted that you have “free will”,  and if you follow their argument, then elementary particles, or, since all of matter is said to be made up of them, matter has free will too. Certainly a spectacular situation, and if you read their writings, I think you will agree that they think it is spectacular too, and they are quite proud of their discovery.

The theorem does not assert that we have free will whatsoever. But if we do then we would not be so free as to withhold the same from those elementary particles; Conway and Kochen’s operative keywords are SPIN, FIN and TWIN. Earlier this year, they announced the Strong Free Will Theorem, which came to my attention and puzzled me quite a lot.

In my experience, it is very hard to cross from science or mathematics to philosophy or metaphysics; in many ways, philosophy and metaphysics are a lot more difficult. In the case of this Free Will Theorem, one might like to perform an experiment to make sure the mathematics corresponds to reality. At the end of section 9, “Historical remarks”, on page 21 of the (earlier) Free Will Theorem article, Conway and Kochen discuss possibilities of such an implementation.

This is because our Free Will assumption requires decisions by a human observer, which current physiology tells us takes a minimum of 1/10 of a second. During such a time interval light will travel almost 20,000 miles, so the experiment cannot be done on Earth.

This is were the following gedanken experiment commences: namely, despite those difficulties, some scientists apply for grants, devise an experiment that can be carried out on Earth, design the equipment, and soon realize that the average person’s free will does not elicit a measurable amount of free will on the part of the elementary particles, at least within their budgetary constraints. They perform some back-of-the-envelope calculations and happily notice a gap: one person in a billion will have sufficient free will.

Jimi Hendrix.

So they call him up and explain the situation, and ask him whether he wants to participate. Jimi reluctantly agrees after some hesitation. They arrange a time, tell him where the lab his, he arrives, and they show him their machine, explain how it works. They tell him that they regret it is loud and noisy, after all it is the first of its kind. When one of its lamps turns from orange to green, he is to push away at the three buttons that they point out, any way he wants to. They will then compare his choices with the elementary particle’s, and graph the results to correlate the free will. He nods, sits down at the chair that is provided, and they start the final preparations. Finally, the lamp turns to green.

Jimi is not pushing any buttons.

They cancel the experiment, and ask him (quite annoyed), why he didn’t follow the instructions. To which he responds, “Well, I wanted to increase volume of your machine, but I couldn’t find the control.”

on github

April 23, 2009 internet No comments

Joined github today, you can look up my (future) public software at

http://github.com/stephanwehner

Added a little project which should make Rails development a little easier when it comes to working with the database directly. For now only for mysql. See my_sql.rb under http://github.com/stephanwehner/railsgoodies.

Thanks to my friend Sam for encouraging me.

Learn about git if you haven’t heared about it,

how to play the moonlight sonata

March 28, 2009 music 1 comment

I’ve been learning the piano over the last few years, off and on; probably less than 1 hour a month on average. Recently it has become a bit more and for the last month or so I’ve been practicing Beethoven’s Moonlight Sonata. I feel it is a good piece for beginners. I’m lucky to have an above average reach, so one note more than an octave is not a stretch for me.

I find it helps a lot to listen to the piece on youtube, and replay certain sections over and over. This got me quite far; but when I got to the 40th bar (of the 1st Movement) I thought it would be good to get some feedback and see what to improve and what’s ok, and if I’m on the right track in general.

So I asked my friend, Andrea, who has been playing a lot longer than me, and she agreed to meet. Because I am not totally happy with our piano, and to make it easier for her, I asked to play at her place. Our piano seems overly sensitive, so that it is not easy to play softly, and consistently so. Sometimes I even think that I hit a key, but no sound resulted (not easy to reproduce either).

What follows only covers how far I know the piece at the moment: the 1st Movement up to bar 42 (where a repetition of an earlier phrase occurs.)

Of course, the way she played it – on the same piano – was a lot better. The way it was better, was, first of all, much more consistency in the right hand: even rhythm, even volume. It was obvious to me that this is important for the piece, but it wasn’t clear to me how much more consistency is possible.

On top of that she applied the pedal almost throughout the whole piece. I had heared that the pedal is important, but not to that extent. Pushing the pedal down is the easiest of course, however, this piece is so delicate that that will not do. The trick is to push the pedal not all the way, but a little more than half-way and, to release the pedal with each chord change, and each time a melody note changes. Once you know, that makes a lot of sense, and it works. But I find that extremely difficult to do. Some scores indicate when to apply, when to release.

The third thing, and I was aware of this, was to bring out the melody notes (“the ones with the stems sticking up”) by playing them louder, compared to the other notes that are played at the same time. I find it pleasing enough to play the piece without this; I think that is also very difficult. Related, around bar 14, where there are two F# half-notes in the right-hand, I was neglecting the second one.

Around bar 28, when a new theme is introduced, she explained to me the meaning of “phrasing”, of how to control the volume, and that the  A in the right hand should be the loudest; equally bars 32 to 40 have phrasing hints; I knew I had ignored those, but now I know how to read them and what they mean. (She also explained that Horowitz manages to regulate the tempo at this part of the piece, by slowing down and speeding up, but such that the total time is still as it should be)

One of the other difficult aspects of the piece is the polyrhythmic motif. (Apparently I’m not doing that badly in that respect.) Apparently, much more advanced players take liberties with this one; this blog entry has sound showing how the author thinks is the right way to play this one.

Thanks again Andrea!

Couple of links for your convenience

Scores

Videos on Youtube

Note: I realize I refer to the idea of “the correct way to play this”, or the “proper way to play”; surely you can ignore that if you prefer.