Write k to encoded output, read k to decode