Mechanical locks operated by cards having permanent magnets