on c19bc7a help sign in
726 lines 14 kB history raw
1:- :~ navhome/'/docs/'
2 sort/'26'
3 title/'3f: Scrambling'
4 ==
6;>
8# 3f: scrambling
10### `++un`*
12Reversible scrambling
14A core that contains arms that perform reversible scrambling operations.
15Used in the `@p` phonetic base.
17#### Source
19```
20 ++ un
21 |%
22```
24---
25### `++wren`
27Conceal structure
29Scrambles a byte-string `pyn` by adding the current position to each
30byte, looking it up in an s-box, and then performing the XOR operation
31on the result, pushing it forward. The inverse of `wred`.
33#### Accepts
35`pyn` is an atom.
37#### Produces
39An atom.
41#### Source
43```
44 ++ wren
45 |= pyn=@ ^- @
46 =+ len=(met 3 pyn)
47 ?: =(0 len)
48 0
49 => .(len (dec len))
50 =+ mig=(zaft (xafo len (cut 3 [len 1] pyn)))
51 %+ can 3
52 %- flop ^- (list [@ @])
53 :- [1 mig]
54 |- ^- (list [@ @])
55 ?: =(0 len)
56 ~
57 => .(len (dec len))
58 =+ mog=(zyft :(mix mig (end 3 1 len) (cut 3 [len 1] pyn)))
59 [[1 mog] $(mig mog)]
60 ::
61```
63#### Examples
65```
66 > `@ux`(wren:un 'testing')
67 0x30.bf6a.b9fe.7d8f
69 > `@ux`'testing'
70 0x67.6e69.7473.6574
72 > `@da`(wred:un (wren:un ~2001.2.5))
73 ~2001.2.5
74```
76---
77### `++wred`
79Restore structure
81Unscrambles a byte-string `cry` by subtracting the current position from
82each byte, looking it up in an s-box, and performing the XOR operation
83on the result, pushing it forward. The inverse of `wren`.
85#### Accepts
87`cry` is an atom.
89#### Produces
91An atom.
93#### Source
95```
96 ++ wred
97 |= cry=@ ^- @
98 =+ len=(met 3 cry)
99 ?: =(0 len)
100 0
101 => .(len (dec len))
102 =+ mig=(cut 3 [len 1] cry)
103 %+ can 3
104 %- flop ^- (list [@ @])
105 :- [1 (xaro len (zart mig))]
106 |- ^- (list [@ @])
107 ?: =(0 len)
108 ~
109 => .(len (dec len))
110 =+ mog=(cut 3 [len 1] cry)
111 [[1 :(mix mig (end 3 1 len) (zyrt mog))] $(mig mog)]
112 ::
113```
115#### Examples
117```
118 > (wred:un 0x30.bf6a.b9fe.7d8f)
119 29.113.321.805.538.676
121 > `@t`(wred:un 0x30.bf6a.b9fe.7d8f)
122 'testing'
124 > (wred:un (wren:un 200.038.426))
125 200.038.426
126```
128---
129### `++xafo`
131Add modulo 255
133Produces the sum of two atoms modulo 255, encoded as a nonzero byte. The inverse
134of `xaro`.
136#### Accepts
138`a` is an atom.
140`b` is an atom.
142#### Produces
144An atom.
146#### Source
148```
149 ++ xafo |=([a=@ b=@] +((mod (add (dec b) a) 255)))
150```
152#### Examples
154```
155 > (xafo:un 5 6)
156 11
158 > (xafo:un 256 20)
159 21
161 > (xafo:un 256 (xaro:un 256 20))
162 20
163```
165---
166### `++xaro`
168Subtract modulo 255
170Produces the sum of two atoms modulo 255, encoded as a nonzero byte. The inverse
171of `xafo`.
173#### Accepts
175`a` is an atom.
177`b` is an atom.
179#### Produces
181An atom.
183#### Source
185```
186 ++ xaro |=([a=@ b=@] +((mod (add (dec b) (sub 255 (mod a 255))) 255)))
187```
189#### Examples
191```
192 > (xaro:un 17 57)
193 40
195 > (xaro:un 265 12)
196 2
198 > (xaro:un 256 (xafo:un 256 20))
199 20
200```
202---
203### `++zaft`
205Look up in 255 sub box
207Looks up a nonzero byte `a` in a substitution box with 255 values, producing a
208unique nonzero byte. The inverse of `zart`.
210#### Accepts
212`a` is an atom of one byte in length.
214#### Produces
216An atom.
218#### Source
220```
221 ++ zaft
222 |= a=@D
223 =+ ^= b
224 0xcc.75bc.86c8.2fb1.9a42.f0b3.79a0.92ca.21f6.1e41.cde5.fcc0.
225 7e85.51ae.1005.c72d.1246.07e8.7c64.a914.8d69.d9f4.59c2.8038.
226 1f4a.dca2.6fdf.66f9.f561.a12e.5a16.f7b0.a39f.364e.cb70.7318.
227 1de1.ad31.63d1.abd4.db68.6a33.134d.a760.edee.5434.493a.e323.
228 930d.8f3d.3562.bb81.0b24.43cf.bea5.a6eb.52b4.0229.06b2.6704.
229 78c9.45ec.d75e.58af.c577.b7b9.c40e.017d.90c3.87f8.96fa.1153.
230 0372.7f30.1c32.ac83.ff17.c6e4.d36d.6b55.e2ce.8c71.8a5b.b6f3.
231 9d4b.eab5.8b3c.e7f2.a8fe.9574.5de0.bf20.3f15.9784.9939.5f9c.
232 e609.564f.d8a4.b825.9819.94aa.2c08.8e4c.9b22.477a.2840.3ed6.
233 3750.6ef1.44dd.89ef.6576.d00a.fbda.9ed2.3b6c.7b0c.bde9.2ade.
234 5c88.c182.481a.1b0f.2bfd.d591.2726.57ba
235 (cut 3 [(dec a) 1] b)
236```
238#### Examples
240```
241 > (zaft:un 0x12)
242 42
244 > (zaft:un 0xff)
245 204
246 > `@ux`(zart:un 204)
247 0xff
249 > (zaft:un 0x0)
250 ! decrement-underflow
251 ! exit
252```
254---
255### `++zart`
257Reverse look up in 255 sub box
259Looks up the index of a nonzero byte `a` in the substitution box with 255
260values, producing a unique nonzero byte. The inverse of `zaft`.
262#### Accepts
264`a` is an atom of one byte in length.
266#### Produces
268An atom.
270#### Source
272```
273 ++ zart :: reverse 255-sbox
274 |= a=@D
275 =+ ^= b
276 0x68.4f07.ea1c.73c9.75c2.efc8.d559.5125.f621.a7a8.8591.5613.
277 dd52.40eb.65a2.60b7.4bcb.1123.ceb0.1bd6.3c84.2906.b164.19b3.
278 1e95.5fec.ffbc.f187.fbe2.6680.7c77.d30e.e94a.9414.fd9a.017d.
279 3a7e.5a55.8ff5.8bf9.c181.e5b6.6ab2.35da.50aa.9293.3bc0.cdc6.
280 f3bf.1a58.4130.f844.3846.744e.36a0.f205.789e.32d8.5e54.5c22.
281 0f76.fce7.4569.0d99.d26e.e879.dc16.2df4.887f.1ffe.4dba.6f5d.
282 bbcc.2663.1762.aed7.af8a.ca20.dbb4.9bc7.a942.834c.105b.c4d4.
283 8202.3e61.a671.90e6.273d.bdab.3157.cfa4.0c2e.df86.2496.f7ed.
284 2b48.2a9d.5318.a343.d128.be9c.a5ad.6bb5.6dfa.c5e1.3408.128d.
285 2c04.0339.97a1.2ff0.49d0.eeb8.6c0a.0b37.b967.c347.d9ac.e072.
286 e409.7b9f.1598.1d3f.33de.8ce3.8970.8e7a
287 (cut 3 [(dec a) 1] b)
288 ::
289```
291#### Examples
293```
294 > `@ux`(zart:un 204)
295 0xff
297 > `@ux`(zart:un 42)
298 0x12
300 > (zaft:un 0x12)
301 42
302```
304---
305### `++zyft`
307Lookup byte in 256 sub box
309Looks up a byte `a` in a substitution box with 256 values, producing a byte. The
310inverse of `zyrt`.
312#### Accepts
314`a` is an atom of one byte in length.
316#### Produces
318An atom.
320#### Source
322```
323 ++ zyft :: forward 256-sbox
324 |= a=@D
325 =+ ^= b
326 0xbb49.b71f.b881.b402.17e4.6b86.69b5.1647.115f.dddb.7ca5.
327 8371.4bd5.19a9.b092.605d.0d9b.e030.a0cc.78ba.5706.4d2d.
328 986a.768c.f8e8.c4c7.2f1c.effe.3cae.01c0.253e.65d3.3872.
329 ce0e.7a74.8ac6.daac.7e5c.6479.44ec.4143.3d20.4af0.ee6c.
330 c828.deca.0377.249f.ffcd.7b4f.eb7d.66f2.8951.042e.595a.
331 8e13.f9c3.a79a.f788.6199.9391.7fab.6200.4ce5.0758.e2f1.
332 7594.c945.d218.4248.afa1.e61a.54fb.1482.bea4.96a2.3473.
333 63c2.e7cb.155b.120a.4ed7.bfd8.b31b.4008.f329.fca3.5380.
334 9556.0cb2.8722.2bea.e96e.3ac5.d1bc.10e3.2c52.a62a.b1d6.
335 35aa.d05e.f6a8.0f3b.31ed.559d.09ad.f585.6d21.fd1d.8d67.
336 370b.26f4.70c1.b923.4684.6fbd.cf8b.5036.0539.9cdc.d93f.
337 9068.1edf.8f33.b632.d427.97fa.9ee1
338 (cut 3 [a 1] b)
339 ::
340```
342#### Examples
344```
345 > (zyft:un 0x12)
346 57
348 > (zyft:un 0x0)
349 225
351 > (zyft:un 0xff)
352 187
353 > `@ux`(zyrt:un 187)
354 0xff
355```
357---
358### `++zyrt`
360Reverse lookup byte in 256 sub box
362Looks up a byte `a` in a substitution box with 256 values, producing a byte.
363The inverse of `zyft`.
365#### Accepts
367`a` is an atom of one byte in length.
369#### Produces
371An atom.
373#### Source
375```
376 ++ zyrt :: reverse 256-sbox
377 |= a=@D
378 =+ ^= b
379 0x9fc8.2753.6e02.8fcf.8b35.2b20.5598.7caa.c9a9.30b0.9b48.
380 47ce.6371.80f6.407d.00dd.0aa5.ed10.ecb7.0f5a.5c3a.e605.
381 c077.4337.17bd.9eda.62a4.79a7.ccb8.44cd.8e64.1ec4.5b6b.
382 1842.ffd8.1dfb.fd07.f2f9.594c.3be3.73c6.2cb6.8438.e434.
383 8d3d.ea6a.5268.72db.a001.2e11.de8c.88d3.0369.4f7a.87e2.
384 860d.0991.25d0.16b9.978a.4bf4.2a1a.e96c.fa50.85b5.9aeb.
385 9dbb.b2d9.a2d1.7bba.66be.e81f.1946.29a8.f5d2.f30c.2499.
386 c1b3.6583.89e1.ee36.e0b4.6092.937e.d74e.2f6f.513e.9615.
387 9c5d.d581.e7ab.fe74.f01b.78b1.ae75.af57.0ec2.adc7.3245.
388 12bf.2314.3967.0806.31dc.cb94.d43f.493c.54a6.0421.c3a1.
389 1c4a.28ac.fc0b.26ca.5870.e576.f7f1.616d.905f.ef41.33bc.
390 df4d.225e.2d56.7fd6.1395.a3f8.c582
391 (cut 3 [a 1] b)
392```
394#### Examples
396```
397 > `@ux`(zyrt:un 57)
398 0x12
400 > `@ux`(zyrt:un 225)
401 0x0
403 > `@ux`(zyrt:un 187)
404 0xff
405 > (zyft:un 0xff)
406 187
407```
409---
410### `++ob`
412Reversible scrambling, v2
414```
415 ++ ob
416 |%
417```
419A core for performing reversible scrambling operations for the `@p` phonetic
420base.
422---
423### `++feen`
425Conceal structure, v2
427Randomly permutes atoms that fit into 17 to 32 bits into one another. If the
428atom fits into 33 to 64 bits, does the same permutation on the low 32 bits
429only. Otherwise, passes the atom through unchanged.
431#### Accepts
433An atom.
435#### Produces
437An atom.
439#### Source
441```
442 ++ feen
443 |= pyn=@ ^- @
444 ?: &((gte pyn 0x1.0000) (lte pyn 0xffff.ffff))
445 (add 0x1.0000 (fice (sub pyn 0x1.0000)))
446 ?: &((gte pyn 0x1.0000.0000) (lte pyn 0xffff.ffff.ffff.ffff))
447 =+ lo=(dis pyn 0xffff.ffff)
448 =+ hi=(dis pyn 0xffff.ffff.0000.0000)
449 %+ con hi
450 (add 0x1.0000 (fice (sub lo 0x1.0000)))
451 pyn
452 ::
453```
455#### Examples
457```
458 > `@p`(feen:ob 111.103)
459 ~mophul-pagwyx
461 > `@p`(feen:ob ~mophul-pagwyx)
462 ~wisfed-lonwes
464 > `@p`(feen:ob (fend:ob ~mophul-pagwyx))
465 ~mophul-pagwyx
467 > `@p`(feen:ob ~wex)
468 ~wex
469```
471---
472### `++fend`
474Restore structure, v2
476Randomly permutes atoms that fit into 17 to 32 bits into one another, and
477randomly permutes the low 32 bits of atoms that fit into 33 to 64 bits;
478otherwise, passes the atom through unchanged. The inverse of the one applied
479by `feen`.
481#### Accepts
483An atom.
485#### Produces
487An atom.
489#### Source
491```
492 ++ fend
493 |= cry=@ ^- @
494 ?: &((gte cry 0x1.0000) (lte cry 0xffff.ffff))
495 (add 0x1.0000 (teil (sub cry 0x1.0000)))
496 ?: &((gte cry 0x1.0000.0000) (lte cry 0xffff.ffff.ffff.ffff))
497 =+ lo=(dis cry 0xffff.ffff)
498 =+ hi=(dis cry 0xffff.ffff.0000.0000)
499 %+ con hi
500 (add 0x1.0000 (teil (sub lo 0x1.0000)))
501 cry
502 ::
503```
505#### Examples
507```
508 > `@p`(fend:ob 111.103)
509 ~doznec-sapfes
511 > `@p`(fend:ob ~doznec-sapfes)
512 ~hanrud-widwyc
514 > `@p`(fend:ob ~wisfed-lonwes)
515 ~mophul-pagwyx
517 > `@p`(fend:ob (feen:ob ~wisfed-lonwes))
518 ~wisfed-lonwes
520 > `@p`(fend:ob ~tarmed)
521 ~tarmed
522```
524---
525### `++fice`
527Feistel-like cipher
529Produces an atom by applying a variant of the Feistel cipher. Unlike
530a conventional Feistel cipher that is its own inverse if keys are used in
531reverse order, this Feistel-like cipher uses two moduli that must be swapped
532when applying the reverse transformation. The inverse of `teil`.
534#### Accepts
536`nor` is an atom.
538#### Produces
540An atom.
542#### Source
544```
545 ++ fice :: adapted from
546 |= nor=@ :: black and rogaway
547 ^- @ :: "ciphers with
548 =+ ^= sel :: arbitrary finite
549 %+ rynd 2 :: domains", 2002
550 %+ rynd 1
551 %+ rynd 0
552 [(mod nor 65.535) (div nor 65.535)]
553 (add (mul 65.535 -.sel) +.sel)
554 ::
555```
557#### Examples
559```
560 > (fice:ob 11)
561 776.343.932
563 > (fice:ob (teil:ob 11))
564 11
565```
567---
568### `++teil`
570Reverse Feistel-like cipher
572Applies the reverse of the Feistel-like cipher applied by `fice`. Unlike
573a conventional Feistel cipher that is its own inverse if keys are used in
574reverse order, this Feistel-like cipher uses two moduli that must be swapped
575when applying the reverse transformation.
577#### Accepts
579`vip` is an atom.
581#### Produces
583An atom.
585#### Source
587```
588 ++ teil :: reverse ++fice
589 |= vip=@
590 ^- @
591 =+ ^= sel
592 %+ rund 0
593 %+ rund 1
594 %+ rund 2
595 [(mod vip 65.535) (div vip 65.535)]
596 (add (mul 65.535 -.sel) +.sel)
597 ::
598```
601#### Examples
603```
604 > (teil:ob 11)
605 514.230.493
607 > (teil:ob (fice:ob 11))
608 11
609```
611---
612### `++rynd`
614Reverse Feistel-like cipher
616A single round of the Feistel-like cipher `fice`. AES ([`aesc`](../3f)) is
617used as the round function. The inverse of `rund`.
619#### Accepts
621`n` is an atom.
623`l` is an atom.
625`r` is an atom.
627#### Produces
629A cell of two atoms.
631#### Source
633```
634 ++ rynd
635 |= [n=@ l=@ r=@]
636 ^- [@ @]
637 :- r
638 ?~ (mod n 2)
639 (~(sum fo 65.535) l (en:aesc (snag n raku) r))
640 (~(sum fo 65.536) l (en:aesc (snag n raku) r))
641```
643#### Examples
645```
646 > (rynd:ob 2 261 9)
647 [9 37.422]
649 > (rynd:ob 2 (rund:ob 2 37.422 9))
650 [261 32.902]
651```
653---
654### `++rund`
656Reverse single Feistel-like
658A single round of the Feistel-like reverse cipher `teil`. AES ([`aesc`](../3f))
659is used as the round function. The inverse of `rynd`.
661#### Accepts
663`n` is an atom.
665`l` is an atom.
667`r` is an atom.
669#### Produces
671A cell of two atoms.
673#### Source
675```
676 ++ rund
677 |= [n=@ l=@ r=@]
678 ^- [@ @]
679 :- r
680 ?~ (mod n 2)
681 (~(dif fo 65.535) l (muk (snag n raku) 2 r))
682 (~(dif fo 65.536) l (muk (snag n raku) 2 r))
683```
685#### Examples
687```
688 > (rund:ob 2 261 9)
689 [9 28.635]
691 > (rund:ob 2 (rynd:ob 2 28.635 9))
692 [261 32.651]
693```
695---
696### `++raku`
698Key list
700Produces a list of arbitrary hexademical keys for use with [`aesc`](../3f).
702#### Produces
704A list of atoms of aura `@ux` (hexadecimal).
706#### Source
708```
709 ++ raku
710 ^- (list @ux)
711 :~ 0xb76d.5eed
712 0xee28.1300
713 0x85bc.ae01
714 0x4b38.7af7
715 ==
716 --
717```
719#### Examples
721```
722 > raku:ob
723 ~[0xb76d.5eed 0xee28.1300 0x85bc.ae01 0x4b38.7af7]
724```
726---