6363 (11) 37 (45) 37 (59) 52 (62) 67
6464>> readonly def
6565
66- /auspost.rspoly [ 48 17 29 30 1 ] readonly def
67-
6866/auspost.latevars dup 8 dict def load /init {
6967
7068 currentglobal
@@ -78,24 +76,39 @@ begin
7876 /rstable 64 64 mul array def
7977 rstable 0 [ 64 {0} repeat ] putinterval
8078 rstable 64 [ 0 1 63 {} for ] putinterval
81- /prev 1 def
79+ 1 % ... prev
8280 64 {
83- /next prev 1 bitshift def
84- next 64 and 0 ne {
85- /next next 67 xor def
86- } if
87- 0 1 63 {
88- /j exch def
89- /nextcell {rstable 64 next mul j add} def
90- nextcell rstable 64 prev mul j add get 1 bitshift put
91- nextcell get 64 and 0 ne {
92- nextcell nextcell get 67 xor put
93- } if
81+ dup 1 bitshift dup 64 and 0 ne {67 xor} if % ... next
82+ 1 index 64 mul % ... prevbase
83+ 1 index 64 mul % ... nextbase
84+ 0 1 63 { % i
85+ rstable 2 index 2 index add
86+ rstable 5 index 4 index add get 1 bitshift
87+ dup 64 and 0 ne {67 xor} if
88+ put
89+ pop % i
9490 } for
95- /prev next def
91+ pop pop exch pop
9692 } repeat
93+ pop
9794 /rstable rstable readonly def
9895
96+ %
97+ % Calculate the generator polynomials
98+ %
99+ /rspoly [ 1 0 0 0 0 ] def
100+ 1 1 4 { % i
101+ 1 1 index bitshift % t = 2^i
102+ exch -1 1 { % j = i -> 1
103+ rspoly 1 index 2 copy 1 sub get % ... rsploy j rsploy[j-1]
104+ rstable rspoly 6 -1 roll get 64 mul 5 index add get % p = rsploy[j] * t
105+ xor put % rspoly[j] = rsploy[j-1] ^ p
106+ } for
107+ rspoly 0 rstable 64 rspoly 0 get mul 4 index add get put % rspoly[0] = rspoly[0] * t
108+ pop % t
109+ } for
110+ /rspoly rspoly readonly def
111+
99112 /init { //auspost.latevars {def} forall } def
100113
101114 end
@@ -239,15 +252,16 @@ begin
239252 encstr i 2 add 1 getinterval cvi add
240253 put
241254 } for
242- rscodes length 5 sub -1 0 {
243- /i exch def
244- 0 1 4 {
245- /j exch def
246- rscodes i j add rscodes i j add get
247- rstable 64 //auspost.rspoly j get mul rscodes i 4 add get add get
248- xor put
249- } for
255+
256+ rscodes length 5 sub -1 0 { % i
257+ 0 1 4 { % j
258+ rscodes 2 index 2 index add 2 copy get % ... rscodes i+j rscodes[i+j]
259+ rstable rspoly 6 -1 roll get 64 mul rscodes 6 index 4 add get add get % p = rspoly[j] * rscodes[i+4]
260+ xor put % rscodes[i+j] = rscodes[i+j] ^ p
261+ } for
262+ pop % i
250263 } for
264+
251265 /checkcode (000000000000) 12 string copy def
252266 0 1 3 {
253267 /i exch def
0 commit comments