jens, not totally sure but this seems to not work at all.
not my code but the rules.

if you have input string which has in second word "K" and at the same position in the cipher "I", you encrypt it with "M"
when you decrypt it, the first "M" in the tableau is for "2"
I thought I was messing things up but it is really clearly in the tableau.
oh, and this was without lower case with input of:
$iRC=vigenere("KIXGOLF KIXGOLF","KIXGOLF") ?? $iRC ????
vigenere($iRC,"KIXGOLF",1) ?

if my case proves right, I have good code at 649 strokes.
I have been looking at the second word table all night and this is the only conclusion I found why the code fails.
do you have any prove that it can work?

download KiXnet