# varicode encoder | 2017-07-14
use strict; use warnings;
use feature qw(say);

my @varicodes = (
	'1010101011',	# 000 NUL
	'1011011011',	# 001 SOH
	'1011101101',	# 002 STX
	'1101110111',	# 003 ETX
	'1011101011',	# 004 EOT
	'1101011111',	# 005 ENQ
	'1011101111',	# 006 ACK
	'1011111101',	# 007 BEL
	'1011111111',	# 010 BS
	'11101111',	# 011 HT
	'11101',	# 012 LF
	'1101101111',	# 013 VT
	'1011011101',	# 014 FF
	'11111',	# 015 CR
	'1101110101',	# 016 SO
	'1110101011',	# 017 SI
	'1011110111',	# 020 DLE
	'1011110101',	# 021 DC1
	'1110101101',	# 022 DC2
	'1110101111',	# 023 DC3
	'1101011011',	# 024 DC4
	'1101101011',	# 025 NAK
	'1101101101',	# 026 SYN
	'1101010111',	# 027 ETB
	'1101111011',	# 030 CAN
	'1101111101',	# 031 EM
	'1110110111',	# 032 SUB
	'1101010101',	# 033 ESC
	'1101011101',	# 034 FS
	'1110111011',	# 035 GS
	'1011111011',	# 036 RS
	'1101111111',	# 037 US
	'1',		# 040 SPC
	'111111111',	# 041 !
	'101011111',	# 042 "
	'111110101',	# 043 #
	'111011011',	# 044 $
	'1011010101',	# 045 %
	'1010111011',	# 046 &
	'101111111',	# 047 '
	'11111011',	# 050 (
	'11110111',	# 051 )
	'101101111',	# 052 *
	'111011111',	# 053 +
	'1110101',	# 054 ,
	'110101',	# 055 -
	'1010111',	# 056 .
	'110101111',	# 057 /
	'10110111',	# 060 0
	'10111101',	# 061 1
	'11101101',	# 062 2
	'11111111',	# 063 3
	'101110111',	# 064 4
	'101011011',	# 065 5
	'101101011',	# 066 6
	'110101101',	# 067 7
	'110101011',	# 070 8
	'110110111',	# 071 9
	'11110101',	# 072 :
	'110111101',	# 073 ;
	'111101101',	# 074 <
	'1010101',	# 075 =
	'111010111',	# 076 >
	'1010101111',	# 077 ?
	'1010111101',	# 100 @
	'1111101',	# 101 A
	'11101011',	# 102 B
	'10101101',	# 103 C
	'10110101',	# 104 D
	'1110111',	# 105 E
	'11011011',	# 106 F
	'11111101',	# 107 G
	'101010101',	# 110 H
	'1111111',	# 111 I
	'111111101',	# 112 J
	'101111101',	# 113 K
	'11010111',	# 114 L
	'10111011',	# 115 M
	'11011101',	# 116 N
	'10101011',	# 117 O
	'11010101',	# 120 P
	'111011101',	# 121 Q
	'10101111',	# 122 R
	'1101111',	# 123 S
	'1101101',	# 124 T
	'101010111',	# 125 U
	'110110101',	# 126 V
	'101011101',	# 127 W
	'101110101',	# 130 X
	'101111011',	# 131 Y
	'1010101101',	# 132 Z
	'111110111',	# 133 [
	'111101111',	# 134 \
	'111111011',	# 135 ]
	'1010111111',	# 136 ^
	'101101101',	# 137 _
	'1011011111',	# 140 `
	'1011',		# 141 a
	'1011111',	# 142 b
	'101111',	# 143 c
	'101101',	# 144 d
	'11',		# 145 e
	'111101',	# 146 f
	'1011011',	# 147 g
	'101011',	# 150 h
	'1101',		# 151 i
	'111101011',	# 152 j
	'10111111',	# 153 k
	'11011',	# 154 l
	'111011',	# 155 m
	'1111',		# 156 n
	'111',		# 157 o
	'111111',	# 160 p
	'110111111',	# 161 q
	'10101',	# 162 r
	'10111',	# 163 s
	'101',		# 164 t
	'110111',	# 165 u
	'1111011',	# 166 v
	'1101011',	# 167 w
	'11011111',	# 170 x
	'1011101',	# 171 y
	'111010101',	# 172 z
	'1010110111',	# 173 {
	'110111011',	# 174 |
	'1010110101',	# 175 }
	'1011010111',	# 176 ~
	'1110110101',	# 177 DEL
);

my $needs_separator = 0;
while (<>) {
	my @chars = split //, $_;
	foreach my $char (@chars) {
		print '00' if $needs_separator;
		my $ord = ord($char);
		my $code;
		if ($ord >= 0 && $ord <= 127) {
			$code = $varicodes[$ord];
		} else {
			$code = $varicodes[ord '?'];
		}
		print $code;
		$needs_separator = 1;
	}
}

Originally posted 2017-07-14 | Last changed 2017-07-14

back to index