Not sure but
Code:
key = (row * 4) + (NCD (col ^ $f))
'NOTE: for 12-key keypad, change to key = (row * 3)
And please use code tags, makes it easier to read...