#!/usr/bin/perl -p use v5.35; my $A = oct $_; for my $B (0 .. 7) { my $a = $B ^ 1; my $new_A = (($A & 0777) << 3) | $a; my $pqr = ($new_A >> $B) & 7; my $axp = $a ^ $pqr; my $out = $axp ^ 4; my $a_bits = sprintf('%012b', $new_A); substr($a_bits, $_, 0) = ' ' for (3, 7, 11); my $pqr_bits = sprintf('%03b', $pqr); say "B = $B: A = xxx $a_bits, pqr = $pqr_bits, a xor pqr = $axp, out = $out"; } $_ = '';