The result of dec2bin() is '0' and '1' not 0 and 1. '0' is char(48) and '1' is char(49), so when you use the '0' and '1' as indices in PC1(key1) you are indexing at locations 48 and 49.
I doubt that you should be applying parity check on one bit at a time. You should probably be taking a smaller number of bits in a group, computing a decimal equivalent, and using that to look up an entry in the parity check matrix.
Best Answer