You either need a way to know when a key is pressed, either by periodic scan or interrupt.
Once you input the 4 digit binary value, you use a lookup table with all the individual bit values, this is then output to the port and turns on the relative bit, a 2n7000 on the output could be used on...