on 140ac0e help sign in
635 lines 14 kB history raw
1# 3f: scrambling
2### `++ob`
4Reversible scrambling core, v2
6 ++ ob
7 |%
9A core for performing reversible scrambling operations for the `@p` phonetic base.
11------------------------------------------------------------------------
13### `++feen`
15Conceal structure, v2
17Randomly permutes atoms that fit into 17 to 32 bits into one another. If the
18atom fits into 33 to 64 bits, does the same permutation on the low 32 bits
19only. Otherwise, passes the atom through unchanged.
21Accepts
22-------
24An atom.
26Produces
27--------
29An atom.
31Source
32------
34 ++ feen :: conceal structure v2
35 |= pyn/@ ^- @
36 ?: &((gte pyn 0x1.0000) (lte pyn 0xffff.ffff))
37 (add 0x1.0000 (fice (sub pyn 0x1.0000)))
38 ?: &((gte pyn 0x1.0000.0000) (lte pyn 0xffff.ffff.ffff.ffff))
39 =+ lo=(dis pyn 0xffff.ffff)
40 =+ hi=(dis pyn 0xffff.ffff.0000.0000)
41 %+ con hi
42 (add 0x1.0000 (fice (sub lo 0x1.0000)))
43 pyn
44 ::
47Examples
48--------
50XX
52------------------------------------------------------------------------
54### `++fend`
56XX
58Randomly permutes atoms that fit into 17 to 32 bits into one another, and
59randomly permutes the low 32 bits of atoms that fit into 33 to 64 bits;
60otherwise, passes the atom through unchanged. The permutation is the inverse of
61the one applied by `++feen`.
63Accepts
64-------
66An atom.
68Produces
69--------
71An atom.
73Source
74------
76 ++ fend :: restore structure v2
77 |= cry/@ ^- @
78 ?: &((gte cry 0x1.0000) (lte cry 0xffff.ffff))
79 (add 0x1.0000 (teil (sub cry 0x1.0000)))
80 ?: &((gte cry 0x1.0000.0000) (lte cry 0xffff.ffff.ffff.ffff))
81 =+ lo=(dis cry 0xffff.ffff)
82 =+ hi=(dis cry 0xffff.ffff.0000.0000)
83 %+ con hi
84 (add 0x1.0000 (teil (sub lo 0x1.0000)))
85 cry
86 ::
88Examples
89--------
91------------------------------------------------------------------------
93### `++fice`
95XX
98Accepts
99-------
101An atom.
103Produces
104--------
106An atom.
108Source
109------
111 ++ fice :: adapted from
112 |= nor/@ :: black and rogaway
113 ^- @ :: "ciphers with
114 =+ ^= sel :: arbitrary finite
115 %+ rynd 2 :: domains", 2002
116 %+ rynd 1
117 %+ rynd 0
118 [(mod nor 65.535) (div nor 65.535)]
119 (add (mul 65.535 -.sel) +.sel)
120 ::
123Examples
124--------
126------------------------------------------------------------------------
128### `++teil`
130XX
132Applies the reverse of the Feistel-like cipher applied by `++fice`. Unlike
133a conventional Feistel cipher that is its own inverse if keys are used in
134reverse order, this Feistel-like cipher uses two moduli that must be swapped
135when applying the reverse transformation.
137Accepts
138-------
140An atom.
142Produces
143--------
145An atom.
147Source
148------
150 ++ teil :: reverse ++fice
151 |= vip/@
152 ^- @
153 =+ ^= sel
154 %+ rund 0
155 %+ rund 1
156 %+ rund 2
157 [(mod vip 65.535) (div vip 65.535)]
158 (add (mul 65.535 -.sel) +.sel)
159 ::
163Examples
164--------
166------------------------------------------------------------------------
168### `++rynd`
170XX
172A single round of the Feistel-like cipher `++fice`. AES (`++aesc`) is
173used as the round function.
175Accepts
176-------
178A cell of three atoms, `n`, `l`, and `r`.
180Produces
181--------
183A cell of two atoms.
185Source
186------
188 ++ rynd :: feistel round
189 |= [n/@ l/@ r/@]
190 ^- [@ @]
191 :- r
192 ?~ (mod n 2)
193 (~(sum fo 65.535) l (en:aesc (snag n raku) r))
194 (~(sum fo 65.536) l (en:aesc (snag n raku) r))
196Examples
197--------
199------------------------------------------------------------------------
201### `++rund`
203XX
205A single round of the Feistel-like reverse cipher `++teil`.
207Accepts
208-------
210A cell of three atoms, `n`, `l`, and `r`.
212Produces
213--------
215A cell of two atoms.
217Source
218------
220 ++ rund :: reverse round
221 |= {n/@ l/@ r/@}
222 ^- {@ @}
223 :- r
224 ?~ (mod n 2)
225 (~(dif fo 65.535) l (en:aesc (snag n raku) r))
226 (~(dif fo 65.536) l (en:aesc (snag n raku) r))
228Examples
229--------
231------------------------------------------------------------------------
233### `++raku`
235XX
238Accepts
239-------
241A list of atoms of odor `@ux` (hexadecimal).
243Produces
244--------
246Arbitrary keys for use with `++aesc`.
248Source
249------
251 ++ raku
252 ^- (list ,@ux)
253 :~ 0x15f6.25e3.083a.eb3e.7a55.d4db.fb99.32a3.
254 43af.2750.219e.8a24.e5f8.fac3.6c36.f968
255 0xf2ff.24fe.54d0.1abd.4b2a.d8aa.4402.8e88.
256 e82f.19ec.948d.b1bb.ed2e.f791.83a3.8133
257 0xa3d8.6a7b.400e.9e91.187d.91a7.6942.f34a.
258 6f5f.ab8e.88b9.c089.b2dc.95a6.aed5.e3a4
259 ==
261Examples
262--------
266***
267### `++un`
269Reversible scrambling core
271 ++ un :: =(x (wred (wren x)))
272 |%
274A core that contains arms that perform reversible scrambling operations.
275Used in the `@p` phonetic base.
277------------------------------------------------------------------------
279### `++wren`
281Conceal structure
283Scrambles a bytestring `pyn` by adding the current position to each
284byte, looking it up in an s-box, and then performing the XOR operation
285on the result, pushing it forward. Produces an atom.
287Accepts
288-------
290`pyn` is an atom.
293Produces
294--------
296An atom.
298Source
299------
301 ++ wren :: conceal structure
302 |= pyn/@ ^- @
303 =+ len=(met 3 pyn)
304 ?: =(0 len)
305 0
306 => .(len (dec len))
307 =+ mig=(zaft (xafo len (cut 3 [len 1] pyn)))
308 %+ can 3
309 %- flop ^- (list {@ @})
310 :- [1 mig]
311 |- ^- (list {@ @})
312 ?: =(0 len)
313 ~
314 => .(len (dec len))
315 =+ mog=(zyft :(mix mig (end 3 1 len) (cut 3 [len 1] pyn)))
316 [[1 mog] $(mig mog)]
317 ::
320Examples
321--------
323 > `@ux`(wren:un 'testing')
324 0x30.bf6a.b9fe.7d8f
325 > `@ux`'testing'
326 0x67.6e69.7473.6574
327 > `@da`(wred:un (wren:un ~2001.2.5))
328 ~2001.2.5
330------------------------------------------------------------------------
332### `++wred`
334Restore structure
336Unscrambles a bytestring `cry` by subtracting the current position from
337each byte, looking it up in an s-box, and performing the XOR operation
338on the result, pushing it forward. Produces an atom.
340Accepts
341-------
343`cry` is an atom.
345Produces
346--------
348Source
349------
351 ++ wred :: restore structure
352 |= cry/@ ^- @
353 =+ len=(met 3 cry)
354 ?: =(0 len)
355 0
356 => .(len (dec len))
357 =+ mig=(cut 3 [len 1] cry)
358 %+ can 3
359 %- flop ^- (list {@ @})
360 :- [1 (xaro len (zart mig))]
361 |- ^- (list {@ @})
362 ?: =(0 len)
363 ~
364 => .(len (dec len))
365 =+ mog=(cut 3 [len 1] cry)
366 [[1 :(mix mig (end 3 1 len) (zyrt mog))] $(mig mog)]
367 ::
369Examples
370--------
372 > (wred:un 0x30.bf6a.b9fe.7d8f)
373 29.113.321.805.538.676
374 > `@t`(wred:un 0x30.bf6a.b9fe.7d8f)
375 'testing'
376 > (wred:un (wren:un 200.038.426))
377 200.038.426
379------------------------------------------------------------------------
381### `++xafo`
383Add modulo 255
385Produces the sum of two atoms modulo 255, encoded as a nonzero byte.
387Accepts
388-------
390A cell of two atoms, `a` and `b`.
392Source
393------
395 ++ xafo |=([a/@ b/@] +((mod (add (dec b) a) 255)))
397Examples
398--------
400 > (xafo:un 5 6)
401 11
402 > (xafo:un 256 20)
403 21
405------------------------------------------------------------------------
407### `++xaro`
409Subtract modulo 255
411Produces the difference between two atoms modulo 255, encoded as a
412nonzero byte.
414Accepts
415-------
417A cell of two atoms, `a` and `b`.
419Produces
420--------
422An atom.
424Source
425------
427 ++ xaro |=([a/@ b/@] +((mod (add (dec b) (sub 255 (mod a 255))) 255)))
429Examples
430--------
432 > (xaro:un 17 57)
433 40
434 > (xaro:un 265 12)
435 2
437------------------------------------------------------------------------
439### `++zaft`
441Look up in 255 sub box
443The inverse of `++zart`. Looks up a nonzero byte `a`in a substiution
444box with 255 values, producing a unique nonzero byte.
446Accepts
447-------
449`a` is an atom of one byte in length.
452Produces
453--------
455An atom.
457Source
458------
460 ++ zaft :: forward 255-sbox
461 |= a/@D
462 =+ ^= b
463 0xcc.75bc.86c8.2fb1.9a42.f0b3.79a0.92ca.21f6.1e41.cde5.fcc0.
464 7e85.51ae.1005.c72d.1246.07e8.7c64.a914.8d69.d9f4.59c2.8038.
465 1f4a.dca2.6fdf.66f9.f561.a12e.5a16.f7b0.a39f.364e.cb70.7318.
466 1de1.ad31.63d1.abd4.db68.6a33.134d.a760.edee.5434.493a.e323.
467 930d.8f3d.3562.bb81.0b24.43cf.bea5.a6eb.52b4.0229.06b2.6704.
468 78c9.45ec.d75e.58af.c577.b7b9.c40e.017d.90c3.87f8.96fa.1153.
469 0372.7f30.1c32.ac83.ff17.c6e4.d36d.6b55.e2ce.8c71.8a5b.b6f3.
470 9d4b.eab5.8b3c.e7f2.a8fe.9574.5de0.bf20.3f15.9784.9939.5f9c.
471 e609.564f.d8a4.b825.9819.94aa.2c08.8e4c.9b22.477a.2840.3ed6.
472 3750.6ef1.44dd.89ef.6576.d00a.fbda.9ed2.3b6c.7b0c.bde9.2ade.
473 5c88.c182.481a.1b0f.2bfd.d591.2726.57ba
474 (cut 3 [(dec a) 1] b)
475 ::
477Examples
478--------
480 > (zaft:un 0x12)
481 42
482 > (zaft:un 0xff)
483 204
484 > (zaft:un 0x0)
485 ! decrement-underflow
486 ! exit
488------------------------------------------------------------------------
490### `++zart`
492Reverse look up in 255 sub box
494The inverse of `++zaft`. Looks up the index of a nonzero byte `a` in
495the substitution box with 255 values, producing a unique nonzero byte.
497Accepts
498-------
500`a` is an atom of one byte in length.
502Produces
503--------
505An atom.
507Source
508------
510 ++ zart :: reverse 255-sbox
511 |= a/@D
512 =+ ^= b
513 0x68.4f07.ea1c.73c9.75c2.efc8.d559.5125.f621.a7a8.8591.5613.
514 dd52.40eb.65a2.60b7.4bcb.1123.ceb0.1bd6.3c84.2906.b164.19b3.
515 1e95.5fec.ffbc.f187.fbe2.6680.7c77.d30e.e94a.9414.fd9a.017d.
516 3a7e.5a55.8ff5.8bf9.c181.e5b6.6ab2.35da.50aa.9293.3bc0.cdc6.
517 f3bf.1a58.4130.f844.3846.744e.36a0.f205.789e.32d8.5e54.5c22.
518 0f76.fce7.4569.0d99.d26e.e879.dc16.2df4.887f.1ffe.4dba.6f5d.
519 bbcc.2663.1762.aed7.af8a.ca20.dbb4.9bc7.a942.834c.105b.c4d4.
520 8202.3e61.a671.90e6.273d.bdab.3157.cfa4.0c2e.df86.2496.f7ed.
521 2b48.2a9d.5318.a343.d128.be9c.a5ad.6bb5.6dfa.c5e1.3408.128d.
522 2c04.0339.97a1.2ff0.49d0.eeb8.6c0a.0b37.b967.c347.d9ac.e072.
523 e409.7b9f.1598.1d3f.33de.8ce3.8970.8e7a
524 (cut 3 [(dec a) 1] b)
525 ::
527Examples
528--------
530 > `@ux`(zart:un 204)
531 0xff
532 > `@ux`(zart:un 42)
533 0x12
535------------------------------------------------------------------------
537### `++zyft`
539Lookup byte in 256 sub box
541The inverse of `++zyrt`. Looks up a byte `a` in a substituion box
542with 256 values, producing a byte.
544Accepts
545-------
547`a` is an atom of one byte in length.
549Produces
550--------
552An atom.
554Source
555------
557 ++ zyft :: forward 256-sbox
558 |= a/@D
559 =+ ^= b
560 0xbb49.b71f.b881.b402.17e4.6b86.69b5.1647.115f.dddb.7ca5.
561 8371.4bd5.19a9.b092.605d.0d9b.e030.a0cc.78ba.5706.4d2d.
562 986a.768c.f8e8.c4c7.2f1c.effe.3cae.01c0.253e.65d3.3872.
563 ce0e.7a74.8ac6.daac.7e5c.6479.44ec.4143.3d20.4af0.ee6c.
564 c828.deca.0377.249f.ffcd.7b4f.eb7d.66f2.8951.042e.595a.
565 8e13.f9c3.a79a.f788.6199.9391.7fab.6200.4ce5.0758.e2f1.
566 7594.c945.d218.4248.afa1.e61a.54fb.1482.bea4.96a2.3473.
567 63c2.e7cb.155b.120a.4ed7.bfd8.b31b.4008.f329.fca3.5380.
568 9556.0cb2.8722.2bea.e96e.3ac5.d1bc.10e3.2c52.a62a.b1d6.
569 35aa.d05e.f6a8.0f3b.31ed.559d.09ad.f585.6d21.fd1d.8d67.
570 370b.26f4.70c1.b923.4684.6fbd.cf8b.5036.0539.9cdc.d93f.
571 9068.1edf.8f33.b632.d427.97fa.9ee1
572 (cut 3 [a 1] b)
573 ::
575Examples
576--------
578 > (zyft:un 0x12)
579 57
580 > (zyft:un 0x0)
581 225
582 > (zyft:un 0xff)
583 187
585------------------------------------------------------------------------
587### `++zyrt`
589Reverse lookup byte in 256 sub box
591The inverse of `++zyft`. Looks up a byte `a` in a substituion box
592with 256 values, producing a byte.
594Accepts
595-------
597`a` is an atom of one byte in length.
599Produces
600--------
602An atom.
604Source
605------
607 ++ zyrt :: reverse 256-sbox
608 |= a/@D
609 =+ ^= b
610 0x9fc8.2753.6e02.8fcf.8b35.2b20.5598.7caa.c9a9.30b0.9b48.
611 47ce.6371.80f6.407d.00dd.0aa5.ed10.ecb7.0f5a.5c3a.e605.
612 c077.4337.17bd.9eda.62a4.79a7.ccb8.44cd.8e64.1ec4.5b6b.
613 1842.ffd8.1dfb.fd07.f2f9.594c.3be3.73c6.2cb6.8438.e434.
614 8d3d.ea6a.5268.72db.a001.2e11.de8c.88d3.0369.4f7a.87e2.
615 860d.0991.25d0.16b9.978a.4bf4.2a1a.e96c.fa50.85b5.9aeb.
616 9dbb.b2d9.a2d1.7bba.66be.e81f.1946.29a8.f5d2.f30c.2499.
617 c1b3.6583.89e1.ee36.e0b4.6092.937e.d74e.2f6f.513e.9615.
618 9c5d.d581.e7ab.fe74.f01b.78b1.ae75.af57.0ec2.adc7.3245.
619 12bf.2314.3967.0806.31dc.cb94.d43f.493c.54a6.0421.c3a1.
620 1c4a.28ac.fc0b.26ca.5870.e576.f7f1.616d.905f.ef41.33bc.
621 df4d.225e.2d56.7fd6.1395.a3f8.c582
622 (cut 3 [a 1] b)
624Examples
625--------
627 > `@ux`(zyrt:un 57)
628 0x12
629 > `@ux`(zyrt:un 225)
630 0x0
631 > `@ux`(zyrt:un 187)
632 0xff
635***