Electrical and mechanical locks