Trigram/hexagram encoder