1 of 5

Mathematica

(I am golfing it. I will post number of bytes when I have done)

(n = Characters /@ {#2, #3, #4};
  Function[b,
    a = PadLeft[IntegerDigits[b, 2], 8];
    x35 = n[[1]] /. Table[ToString[i - 1] -> 2 + a[[i]], {i, 8}];
    StringJoin @@ 
     Table[If[NumberQ[k = x35[[i]]], n[[k, i]], cmask[[i]]], {i, 
       Length[x35]}]
    ] /@ #1
  ) &