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