Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/seed/text/tests/gen.om # omega-mv Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance. Brought by drakestapleton Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / seed / text / tests / gen.om` 1424 lines ยท 20145 bytes Raw Blame History 1 om2 2 note seed/text/tests/gen.om: the cases and their expected answers for seed/text/text.om, in seeded Omega. 3 note Usage: gen OUTDIR. Writes OUTDIR/cases-K.bin and OUTDIR/want-K.txt, K = 0, 1, ..., then prints 4 note "cases files=N". It replaces tests/gen.py (Python) and writes the same bytes for the same rows. 5 note The answers are computed here by separate plain code (byte loops, digit-string comparison against 6 note the range limits, the Unicode table 3-7 of well-formed UTF-8), never by text.om, so a rule that 7 note text.om gets wrong shows as a mismatch. The random cases come from MT19937 seeded with `20261108` 8 note the way CPython seeds random.Random(`20261108`), drawn the way CPython 3.12 draws them 9 note (getrandbits by 32-bit words, _randbelow by rejection, random() from two words), so the rows are 10 note the ones gen.py wrote. Record layout (txdrv.om): op byte; byte strings as u32 little-endian 11 note length + bytes; numbers u64 little-endian. Every write is checked: a failure exits 80. 12 13 const LIMIT ulong `2900000` 14 const NONE ulong `18446744073709551615` 15 note random() < p is a53 * 2^-53 < p, with a53 = (w1 >> 5) * 2^26 + (w2 >> 6): exactly a53 < ceil(p * 2^53) 16 note for the binary64 p (WolframLanguageEvaluator Ceiling[SetPrecision[p, Infinity]*2^53]). 17 const T30 ulong `2702159776422298` 18 const T05 ulong `450359962737050` 19 const T50 ulong `4503599627370496` 20 const T20 ulong `1801439850948199` 21 22 text tcase "/cases-" 23 text twant "/want-" 24 text tbin ".bin" 25 text ttxt ".txt" 26 text tfiles "cases files=" 27 text terr "err " 28 text tok "ok " 29 text tneedle "needle" 30 text tneedlx "needlex" 31 text t25 "0123456789abcdefABCDEF-+ " 32 text tu64 "`18446744073709551615`" 33 text ti63p "`9223372036854775807`" 34 text ti63n "`9223372036854775808`" 35 text tedge "|0|00|1|`18446744073709551615`|`18446744073709551616`|`18446744073709551619`|`18446744073709551620`|`99999999999999999999`|`000000000000000000000018446744073709551615`|1x|x| 1|1 |+1|-|-0|-1|`9223372036854775807`|`9223372036854775808`|-`9223372036854775808`|-`9223372036854775809`|--1|1-|ffffffffffffffff|FFFFFFFFFFFFFFFF|`10000000000000000`|0fffffffffffffffF|g|0x10|99999999999999999999x" 36 37 global cb uchar `2900000` 38 global cn ulong 1 39 global wb uchar `1048576` 40 global wn ulong 1 41 global wfd long 1 42 global nf ulong 1 43 global od uchar 4096 44 global odn ulong 1 45 global pb uchar 4200 46 global pn ulong 1 47 global nb uchar 24 48 global ft uchar 72 49 global ftn ulong 1 50 global eb uchar 4 51 global mt uint 624 52 global mi ulong 1 53 global ga uchar 262144 54 global gb uchar 262144 55 global gl ulong 2 56 57 fn ck yes bool to void 58 if not yes 59 exit 80 60 end 61 end 62 63 note ======== MT19937, seeded as CPython's init_by_array with the one key word `20261108` 64 fn mtseed to void 65 put mt 0 uint `19650218` 66 for i ulong 623 67 p = get mt i 68 put mt add i 1 add mul `1812433253` xor p shr p 30 uint add i 1 69 end 70 i = ulong 1 71 for c1 ulong 624 72 p = get mt sub i 1 73 put mt i add xor get mt i mul xor p shr p 30 `1664525` uint `20261108` 74 i = add i 1 75 if ge i 624 76 put mt 0 get mt 623 77 i = 1 78 end 79 end 80 for c2 ulong 623 81 p = get mt sub i 1 82 put mt i sub xor get mt i mul xor p shr p 30 `1566083941` uint i 83 i = add i 1 84 if ge i 624 85 put mt 0 get mt 623 86 i = 1 87 end 88 end 89 put mt 0 0x80000000 90 put mi 0 624 91 end 92 93 fn mtgen to void 94 for k ulong 624 95 y = or and get mt k 0x80000000 and get mt rem add k 1 624 0x7fffffff 96 v = xor get mt rem add k 397 624 shr y 1 97 if ne and y 1 0 98 v = xor v 0x9908b0df 99 end 100 put mt k v 101 end 102 put mi 0 0 103 end 104 105 fn rnd32 to uint 106 if ge get mi 0 624 107 mtgen 108 end 109 i = get mi 0 110 y = get mt i 111 put mi 0 add i 1 112 y = xor y shr y 11 113 y = xor y and shl y 7 0x9d2c5680 114 y = xor y and shl y 15 0xefc60000 115 y = xor y shr y 18 116 ret y 117 end 118 119 note getrandbits(k) for k 1..32 120 fn rbits k ulong to ulong 121 ret ulong shr rnd32 sub 32 k 122 end 123 124 fn blen n ulong to ulong 125 k = ulong 0 126 x = n 127 while gt x 0 bound 65 128 x = shr x 1 129 k = add k 1 130 end 131 ret k 132 end 133 134 note _randbelow(n), n 1 .. 2^32 - 1: getrandbits(bit_length n) until below n 135 fn rbelow n ulong to ulong 136 k = blen n 137 r = rbits k 138 while ge r n bound `1000000` 139 r = rbits k 140 end 141 ret r 142 end 143 144 note _randbelow(2^64): getrandbits(65) is three words, low first, the third shifted right by 31 145 fn r64 to ulong 146 w0 = ulong rnd32 147 w1 = ulong rnd32 148 w2 = shr rnd32 31 149 while ne w2 0 bound `1000000` 150 w0 = ulong rnd32 151 w1 = ulong rnd32 152 w2 = shr rnd32 31 153 end 154 ret or w0 shl w1 32 155 end 156 157 note random() as the 53-bit integer a53 (see T30) 158 fn rrand to ulong 159 a = ulong shr rnd32 5 160 b = ulong shr rnd32 6 161 ret add mul a `67108864` b 162 end 163 164 note ======== output: want lines go through wb to the open want file, records into cb 165 fn dig v ulong to ulong 166 x = v 167 i = ulong 0 168 put nb i uchar add rem x 10 48 169 x = div x 10 170 i = add i 1 171 while gt x 0 bound 20 172 put nb i uchar add rem x 10 48 173 x = div x 10 174 i = add i 1 175 end 176 ret i 177 end 178 179 fn wb1 c uchar to void 180 n = get wn 0 181 put wb n c 182 put wn 0 add n 1 183 end 184 185 fn wtx t view uchar * to void 186 for i ulong len t 187 wb1 get t i 188 end 189 end 190 191 fn wnum v ulong to void 192 i = dig v 193 while gt i 0 bound 20 194 i = sub i 1 195 wb1 get nb i 196 end 197 end 198 199 fn wop c uchar to void 200 wb1 c 201 wb1 32 202 end 203 204 fn wflush to void 205 fd = int sub get wfd 0 1 206 n = get wn 0 207 off = ulong 0 208 while lt off n bound `1000000` 209 w = write fd wb off sub n off 210 ck gt w 0 211 off = add off ulong w 212 end 213 put wn 0 0 214 end 215 216 fn wend to void 217 wb1 10 218 if gt get wn 0 `1040000` 219 wflush 220 end 221 end 222 223 fn cb1 c uchar to void 224 n = get cn 0 225 put cb n c 226 put cn 0 add n 1 227 end 228 229 fn cbn v ulong k ulong to void 230 for i ulong k 231 cb1 uchar and shr v mul i 8 255 232 end 233 end 234 235 fn cbga n ulong to void 236 for i ulong n 237 cb1 get ga i 238 end 239 end 240 241 fn cbgb n ulong to void 242 for i ulong n 243 cb1 get gb i 244 end 245 end 246 247 fn pb1 c uchar to void 248 n = get pn 0 249 put pb n c 250 put pn 0 add n 1 251 end 252 253 fn pbtx t view uchar * to void 254 for i ulong len t 255 pb1 get t i 256 end 257 end 258 259 note mkpath kind: OUTDIR/cases-K.bin (kind 0) or OUTDIR/want-K.txt (kind 1) into pb; its length 260 fn mkpath kind ulong to ulong 261 put pn 0 0 262 for i ulong get odn 0 263 pb1 get od i 264 end 265 if eq kind 0 266 pbtx tcase 267 else 268 pbtx twant 269 end 270 j = dig get nf 0 271 while gt j 0 bound 20 272 j = sub j 1 273 pb1 get nb j 274 end 275 if eq kind 0 276 pbtx tbin 277 else 278 pbtx ttxt 279 end 280 ret get pn 0 281 end 282 283 fn openw to void 284 n = mkpath 1 285 fd = fopen pb 0 n 577 420 286 ck ge fd 0 287 put wfd 0 add fd 1 288 end 289 290 fn flush to void 291 n = get cn 0 292 if eq n 0 293 ret 294 end 295 p = mkpath 0 296 fd = int fopen pb 0 p 577 420 297 ck ge fd 0 298 off = ulong 0 299 while lt off n bound `1000000` 300 w = write fd cb off sub n off 301 ck gt w 0 302 off = add off ulong w 303 end 304 ck eq fclose fd 0 305 put cn 0 0 306 wflush 307 ck eq fclose int sub get wfd 0 1 0 308 put wfd 0 0 309 put nf 0 add get nf 0 1 310 end 311 312 note reserve L: start a new cases file first when this record of L bytes would pass LIMIT 313 fn reserve l ulong to void 314 if gt add get cn 0 l LIMIT 315 flush 316 end 317 if eq get wfd 0 0 318 openw 319 end 320 end 321 322 note ======== bytes: equality and order 323 fn cmpab la ulong lb ulong to ulong 324 m = la 325 if lt lb m 326 m = lb 327 end 328 for i ulong m 329 x = get ga i 330 y = get gb i 331 if ne x y 332 if lt x y 333 ret 0 334 end 335 ret 2 336 end 337 end 338 if lt la lb 339 ret 0 340 end 341 if gt la lb 342 ret 2 343 end 344 ret 1 345 end 346 347 fn cmpcase to void 348 la = get gl 0 349 lb = get gl 1 350 reserve add add 9 la lb 351 cb1 69 352 cbn la 4 353 cbga la 354 cbn lb 4 355 cbgb lb 356 c = cmpab la lb 357 wop 69 358 if eq c 1 359 wb1 49 360 else 361 wb1 48 362 end 363 wb1 32 364 if eq c 0 365 wb1 45 366 wb1 49 367 else 368 if eq c 1 369 wb1 48 370 else 371 wb1 49 372 end 373 end 374 wend 375 end 376 377 note ======== search 378 fn same i ulong lb ulong to bool 379 for j ulong lb 380 if ne get ga add i j get gb j 381 ret false 382 end 383 end 384 ret true 385 end 386 387 fn findat la ulong lb ulong frm ulong to ulong 388 if gt frm la 389 ret NONE 390 end 391 if gt lb sub la frm 392 ret NONE 393 end 394 stop = sub la lb 395 i = frm 396 while le i stop bound `1000000` 397 if same i lb 398 ret i 399 end 400 i = add i 1 401 end 402 ret NONE 403 end 404 405 fn findcase frm ulong to void 406 la = get gl 0 407 lb = get gl 1 408 reserve add add 17 la lb 409 cb1 70 410 cbn la 4 411 cbga la 412 cbn lb 4 413 cbgb lb 414 cbn frm 8 415 r = findat la lb frm 416 wop 70 417 if eq r NONE 418 wb1 110 419 else 420 wnum r 421 end 422 wend 423 end 424 425 note ======== fields 426 fn splcase sep uchar to void 427 la = get gl 0 428 reserve add 6 la 429 cb1 83 430 cbn la 4 431 cbga la 432 cb1 sep 433 wop 83 434 cnt = ulong 1 435 for i ulong la 436 if eq get ga i sep 437 cnt = add cnt 1 438 end 439 end 440 wnum cnt 441 p = ulong 0 442 for j ulong la 443 if eq get ga j sep 444 wb1 32 445 wnum sub j p 446 p = add j 1 447 end 448 end 449 wb1 32 450 wnum sub la p 451 wend 452 end 453 454 note ======== integer text 455 fn isdig c uchar to bool 456 ret and ge c 48 le c 57 457 end 458 459 fn ishex c uchar to bool 460 ret or isdig c or and ge c 97 le c 102 and ge c 65 le c 70 461 end 462 463 fn hexval c uchar to ulong 464 if le c 57 465 ret ulong sub c 48 466 end 467 if ge c 97 468 ret ulong sub c 87 469 end 470 ret ulong sub c 55 471 end 472 473 note digover z nd t: the digits ga[z .. z+nd), no leading zero, are a number above the digits of t 474 fn digover z ulong nd ulong t view uchar * to bool 475 if ne nd len t 476 ret gt nd len t 477 end 478 for i ulong nd 479 x = get ga add z i 480 y = get t i 481 if ne x y 482 ret gt x y 483 end 484 end 485 ret false 486 end 487 488 note pform op s: every byte of ga[s ..) has the form of op (decimal digits, or hex digits for H), and 489 note there is at least one 490 fn pform op uchar s ulong to bool 491 la = get gl 0 492 ok = gt la s 493 i = s 494 while lt i la bound `1000000` 495 g = isdig get ga i 496 if eq op 72 497 g = ishex get ga i 498 end 499 if not g 500 ok = false 501 end 502 i = add i 1 503 end 504 ret ok 505 end 506 507 note pover op ng z: the digits ga[z ..), no leading zero, are out of range for op (ng: after a '-') 508 fn pover op uchar ng bool z ulong to bool 509 nd = sub get gl 0 z 510 if eq op 72 511 ret gt nd 16 512 end 513 if eq op 68 514 ret digover z nd tu64 515 end 516 if ng 517 ret digover z nd ti63n 518 end 519 ret digover z nd ti63p 520 end 521 522 fn pvalue base ulong z ulong to ulong 523 la = get gl 0 524 v = ulong 0 525 j = z 526 while lt j la bound `1000000` 527 v = add mul v base hexval get ga j 528 j = add j 1 529 end 530 ret v 531 end 532 533 note pres op: the answer after "D ", "H " or "I ": err 1 empty, err 2 a byte outside the form, err 3 out 534 note of range, else ok and the value 535 fn pres op uchar to void 536 la = get gl 0 537 if eq la 0 538 wtx terr 539 wb1 49 540 ret 541 end 542 s = ulong 0 543 ng = false 544 if and eq op 73 eq get ga 0 45 545 ng = true 546 s = 1 547 end 548 if not pform op s 549 wtx terr 550 wb1 50 551 ret 552 end 553 z = s 554 while and lt z la eq get ga z 48 bound `1000000` 555 z = add z 1 556 end 557 if pover op ng z 558 wtx terr 559 wb1 51 560 ret 561 end 562 base = ulong 10 563 if eq op 72 564 base = 16 565 end 566 v = pvalue base z 567 wtx tok 568 if and ng ne v 0 569 wb1 45 570 end 571 wnum v 572 end 573 574 fn parcase op uchar to void 575 la = get gl 0 576 reserve add 5 la 577 cb1 op 578 cbn la 4 579 cbga la 580 wop op 581 pres op 582 wend 583 end 584 585 fn par3 to void 586 parcase 68 587 parcase 72 588 parcase 73 589 end 590 591 note ======== number text: ft gets the text, ftn its length 592 fn fdec v ulong to void 593 n = dig v 594 for i ulong n 595 put ft i get nb sub sub n i 1 596 end 597 put ftn 0 n 598 end 599 600 fn fsig u ulong to void 601 if lt u 0x8000000000000000 602 fdec u 603 ret 604 end 605 m = sub 0 u 606 n = dig m 607 put ft 0 45 608 for i ulong n 609 put ft add i 1 get nb sub sub n i 1 610 end 611 put ftn 0 add n 1 612 end 613 614 fn fhex v ulong w ulong to void 615 n = ulong 1 616 x = shr v 4 617 while gt x 0 bound 16 618 n = add n 1 619 x = shr x 4 620 end 621 if lt n w 622 n = w 623 end 624 x = v 625 j = n 626 while gt j 0 bound 64 627 j = sub j 1 628 d = uchar and x 15 629 c = add d 48 630 if gt d 9 631 c = add d 87 632 end 633 put ft j c 634 x = shr x 4 635 end 636 put ftn 0 n 637 end 638 639 fn fmtcase op uchar v ulong w ulong cap ulong to void 640 reserve 25 641 cb1 op 642 cbn v 8 643 cbn w 8 644 cbn cap 8 645 if eq op 102 646 fdec v 647 end 648 if eq op 120 649 fhex v w 650 end 651 if eq op 103 652 fsig v 653 end 654 wop op 655 n = get ftn 0 656 if gt n cap 657 wb1 69 658 else 659 for i ulong n 660 wb1 get ft i 661 end 662 end 663 wend 664 end 665 666 fn fmtx v ulong w ulong to void 667 fhex v w 668 l = get ftn 0 669 fmtcase 120 v w sub l 1 670 fmtcase 120 v w 16 671 fmtcase 120 v w 64 672 end 673 674 fn fmtv v ulong to void 675 fdec v 676 l = get ftn 0 677 fmtcase 102 v 0 0 678 fmtcase 102 v 0 1 679 fmtcase 102 v 0 sub l 1 680 fmtcase 102 v 0 l 681 fmtcase 102 v 0 20 682 fmtcase 102 v 0 64 683 fmtx v 0 684 fmtx v 1 685 fmtx v 8 686 fmtx v 16 687 end 688 689 fn fmtg u ulong to void 690 fsig u 691 l = get ftn 0 692 fmtcase 103 u 0 sub l 1 693 fmtcase 103 u 0 l 694 fmtcase 103 u 0 64 695 end 696 697 note ======== UTF-8 (Unicode table 3-7): sequence length by lead byte (0: never a lead), second-byte range 698 fn u8need c uchar to ulong 699 if lt c 0x80 700 ret 1 701 end 702 if lt c 0xc2 703 ret 0 704 end 705 if lt c 0xe0 706 ret 2 707 end 708 if lt c 0xf0 709 ret 3 710 end 711 if lt c 0xf5 712 ret 4 713 end 714 ret 0 715 end 716 717 fn u8lo c uchar to uchar 718 if eq c 0xe0 719 ret 0xa0 720 end 721 if eq c 0xf0 722 ret 0x90 723 end 724 ret 0x80 725 end 726 727 fn u8hi c uchar to uchar 728 if eq c 0xed 729 ret 0x9f 730 end 731 if eq c 0xf4 732 ret 0x8f 733 end 734 ret 0xbf 735 end 736 737 note u8bad i k: the k-byte sequence led at ga[i] has a byte outside its range (all k bytes present) 738 fn u8bad i ulong k ulong to bool 739 c = get ga i 740 s = get ga add i 1 741 if or lt s u8lo c gt s u8hi c 742 ret true 743 end 744 j = ulong 2 745 while lt j k bound 4 746 t = get ga add i j 747 if or lt t 0x80 gt t 0xbf 748 ret true 749 end 750 j = add j 1 751 end 752 ret false 753 end 754 755 note u8val: the length when ga is well-formed, else the index of the lead of the first sequence that is 756 note ill-formed or cut off by the end 757 fn u8val to ulong 758 la = get gl 0 759 i = ulong 0 760 while lt i la bound `1000000` 761 k = u8need get ga i 762 if eq k 0 763 ret i 764 end 765 if gt k 1 766 if gt add i k la 767 ret i 768 end 769 if u8bad i k 770 ret i 771 end 772 end 773 i = add i k 774 end 775 ret la 776 end 777 778 fn u8case to void 779 la = get gl 0 780 reserve add 5 la 781 cb1 85 782 cbn la 4 783 cbga la 784 wop 85 785 wnum u8val 786 wend 787 end 788 789 note u8enc cp: the UTF-8 bytes of cp (below 0x110000) into eb; their count 790 fn u8enc cp ulong to ulong 791 if lt cp 0x80 792 put eb 0 uchar cp 793 ret 1 794 end 795 if lt cp 0x800 796 put eb 0 uchar or 0xc0 shr cp 6 797 put eb 1 uchar or 0x80 and cp 0x3f 798 ret 2 799 end 800 if lt cp 0x10000 801 put eb 0 uchar or 0xe0 shr cp 12 802 put eb 1 uchar or 0x80 and shr cp 6 0x3f 803 put eb 2 uchar or 0x80 and cp 0x3f 804 ret 3 805 end 806 put eb 0 uchar or 0xf0 shr cp 18 807 put eb 1 uchar or 0x80 and shr cp 12 0x3f 808 put eb 2 uchar or 0x80 and shr cp 6 0x3f 809 put eb 3 uchar or 0x80 and cp 0x3f 810 ret 4 811 end 812 813 fn u8app cp ulong to void 814 n = u8enc cp 815 la = get gl 0 816 for i ulong n 817 put ga add la i get eb i 818 end 819 put gl 0 add la n 820 end 821 822 note decres: the answer after "P ": the first code point and its length, or n 823 fn decres to void 824 la = get gl 0 825 c = get ga 0 826 k = u8need c 827 if eq k 0 828 wb1 110 829 ret 830 end 831 if eq k 1 832 wnum ulong c 833 wb1 32 834 wb1 49 835 ret 836 end 837 if lt la k 838 wb1 110 839 ret 840 end 841 if u8bad 0 k 842 wb1 110 843 ret 844 end 845 cp = ulong and c 0x1f 846 if eq k 3 847 cp = ulong and c 0x0f 848 end 849 if eq k 4 850 cp = ulong and c 0x07 851 end 852 for j ulong sub k 1 853 cp = or shl cp 6 ulong and get ga add j 1 0x3f 854 end 855 wnum cp 856 wb1 32 857 wnum k 858 end 859 860 fn deccase to void 861 la = get gl 0 862 reserve add 5 la 863 cb1 80 864 cbn la 4 865 cbga la 866 wop 80 867 decres 868 wend 869 end 870 871 fn enccase cp ulong cap ulong to void 872 reserve 17 873 cb1 81 874 cbn cp 8 875 cbn cap 8 876 wop 81 877 if or gt cp 0x10ffff and ge cp 0xd800 le cp 0xdfff 878 wb1 82 879 wend 880 ret 881 end 882 n = u8enc cp 883 if gt n cap 884 wb1 69 885 wend 886 ret 887 end 888 for i ulong n 889 e = get eb i 890 wb1 hexc shr e 4 891 wb1 hexc and e 15 892 end 893 wend 894 end 895 896 fn hexc d uchar to uchar 897 if lt d 10 898 ret add d 48 899 end 900 ret add d 87 901 end 902 903 note ======== the case sections, in gen.py's order 904 fn rab5 to uchar 905 i = rbelow 5 906 if eq i 0 907 ret 97 908 end 909 if eq i 1 910 ret 98 911 end 912 if eq i 2 913 ret 127 914 end 915 if eq i 3 916 ret 128 917 end 918 ret 255 919 end 920 921 fn seccmp to void 922 for t ulong 3000 923 la = rbelow 9 924 for i1 ulong la 925 put ga i1 rab5 926 end 927 put gl 0 la 928 if lt rrand T30 929 for i2 ulong la 930 put gb i2 get ga i2 931 end 932 put gl 1 la 933 else 934 lb = rbelow 9 935 for i3 ulong lb 936 put gb i3 rab5 937 end 938 put gl 1 lb 939 end 940 cmpcase 941 end 942 end 943 944 fn cpab n ulong to void 945 for i ulong n 946 put gb i get ga i 947 end 948 put gl 1 n 949 end 950 951 fn flipcmp ix ulong to void 952 cpab 200000 953 put gb ix xor get gb ix 0x80 954 cmpcase 955 end 956 957 fn secbig to void 958 for i ulong 200000 959 put ga i uchar rbelow 256 960 end 961 put gl 0 200000 962 cpab 200000 963 cmpcase 964 flipcmp 0 965 flipcmp 65535 966 flipcmp 65536 967 flipcmp 65537 968 flipcmp 131072 969 flipcmp 199999 970 cpab 199999 971 cmpcase 972 cpab 200000 973 put gl 0 199999 974 cmpcase 975 put gl 0 0 976 put gl 1 0 977 cmpcase 978 end 979 980 fn secfind to void 981 for t ulong 3000 982 lh = rbelow 12 983 for i1 ulong lh 984 put ga i1 uchar add 97 rbelow 2 985 end 986 put gl 0 lh 987 ln = rbelow 4 988 for i2 ulong ln 989 put gb i2 uchar add 97 rbelow 2 990 end 991 put gl 1 ln 992 findcase rbelow 14 993 end 994 end 995 996 fn gbtx t view uchar * to void 997 for i ulong len t 998 put gb i get t i 999 end 1000 put gl 1 len t 1001 end 1002 1003 fn sechay to void 1004 for i ulong 250000 1005 put ga i uchar add 97 rbelow 2 1006 end 1007 for j ulong 6 1008 put ga add 250000 j get tneedle j 1009 end 1010 for k ulong 10 1011 put ga add 250006 k 97 1012 end 1013 la = ulong 250016 1014 put gl 0 la 1015 gbtx tneedle 1016 findcase 0 1017 findcase 65536 1018 findcase 250000 1019 findcase 250001 1020 findcase sub la 6 1021 findcase la 1022 findcase add la 1 1023 put gl 1 0 1024 findcase la 1025 put gl 0 0 1026 findcase 0 1027 findcase 1 1028 put gl 0 la 1029 gbtx tneedlx 1030 findcase 0 1031 end 1032 1033 fn secsplit to void 1034 for t ulong 2000 1035 l = rbelow 12 1036 for i ulong l 1037 c = uchar 97 1038 if eq rbelow 2 1 1039 c = 44 1040 end 1041 put ga i c 1042 end 1043 put gl 0 l 1044 splcase 44 1045 end 1046 for j ulong 140000 1047 put ga j 97 1048 end 1049 put ga 140000 44 1050 put ga 140001 98 1051 put ga 140002 98 1052 put ga 140003 98 1053 put gl 0 140004 1054 splcase 44 1055 end 1056 1057 fn secedge to void 1058 p = ulong 0 1059 for i ulong add len tedge 1 1060 cut = false 1061 if eq i len tedge 1062 cut = true 1063 else 1064 if eq get tedge i 124 1065 cut = true 1066 end 1067 end 1068 if cut 1069 for j ulong sub i p 1070 put ga j get tedge add p j 1071 end 1072 put gl 0 sub i p 1073 par3 1074 p = add i 1 1075 end 1076 end 1077 for k ulong 100000 1078 put ga k 48 1079 end 1080 put ga 100000 55 1081 put gl 0 100001 1082 par3 1083 end 1084 1085 fn secbyte to void 1086 for a ulong 256 1087 put ga 0 uchar a 1088 put ga 1 49 1089 put gl 0 1 1090 parcase 68 1091 put gl 0 2 1092 parcase 68 1093 put gl 0 1 1094 parcase 72 1095 put gl 0 2 1096 parcase 72 1097 put gl 0 1 1098 parcase 73 1099 put gl 0 2 1100 parcase 73 1101 end 1102 end 1103 1104 fn secprnd to void 1105 for t ulong 4000 1106 k = add 1 rbelow 22 1107 for i ulong k 1108 c = uchar 0 1109 if lt rrand T05 1110 c = get t25 rbelow 25 1111 else 1112 c = uchar add 48 rbelow 10 1113 end 1114 put ga i c 1115 end 1116 put gl 0 k 1117 par3 1118 end 1119 end 1120 1121 fn secfmt to void 1122 fmtv 0 1123 fmtv 1 1124 fmtv 9 1125 fmtv 10 1126 fmtv 99 1127 fmtv 100 1128 fmtv 0xffffffffffffffff 1129 fmtv 0xfffffffffffffffe 1130 fmtv 0x8000000000000000 1131 fmtv 0x7fffffffffffffff 1132 for t ulong 2000 1133 fmtv r64 1134 end 1135 fmtg 0 1136 fmtg 0xffffffffffffffff 1137 fmtg 1 1138 fmtg 0x8000000000000000 1139 fmtg 0x7fffffffffffffff 1140 fmtg 0x8000000000000001 1141 for u ulong 2000 1142 fmtg xor r64 0x8000000000000000 1143 end 1144 end 1145 1146 fn third i ulong to uchar 1147 if eq i 0 1148 ret 0x00 1149 end 1150 if eq i 1 1151 ret 0x7f 1152 end 1153 if eq i 2 1154 ret 0x80 1155 end 1156 if eq i 3 1157 ret 0x8f 1158 end 1159 if eq i 4 1160 ret 0x90 1161 end 1162 if eq i 5 1163 ret 0xa0 1164 end 1165 if eq i 6 1166 ret 0xbf 1167 end 1168 if eq i 7 1169 ret 0xc0 1170 end 1171 ret 0xff 1172 end 1173 1174 fn secu8 to void 1175 for a ulong 256 1176 put ga 0 uchar a 1177 put gl 0 1 1178 u8case 1179 end 1180 put gl 0 2 1181 for a2 ulong 256 1182 for b2 ulong 256 1183 put ga 0 uchar a2 1184 put ga 1 uchar b2 1185 u8case 1186 end 1187 end 1188 put gl 0 3 1189 for a3 ulong 16 1190 for b3 ulong 256 1191 for c3 ulong 256 1192 put ga 0 uchar add 0xe0 a3 1193 put ga 1 uchar b3 1194 put ga 2 uchar c3 1195 u8case 1196 end 1197 end 1198 end 1199 put gl 0 4 1200 for a4 ulong 5 1201 for b4 ulong 64 1202 for c4 ulong 9 1203 for e4 ulong 9 1204 put ga 0 uchar add 0xf0 a4 1205 put ga 1 uchar add 0x80 b4 1206 put ga 2 third c4 1207 put ga 3 third e4 1208 u8case 1209 end 1210 end 1211 end 1212 end 1213 end 1214 1215 fn pick5 p ulong c0 ulong c1 ulong c2 ulong c3 ulong c4 ulong to ulong 1216 if eq p 0 1217 ret c0 1218 end 1219 if eq p 1 1220 ret c1 1221 end 1222 if eq p 2 1223 ret c2 1224 end 1225 if eq p 3 1226 ret c3 1227 end 1228 ret c4 1229 end 1230 1231 fn u8mix to void 1232 put gl 0 0 1233 cnt = rbelow 6 1234 for j ulong cnt 1235 c0 = rbelow 0x80 1236 c1 = add 0x80 rbelow sub ulong 0x800 0x80 1237 c2 = add 0x800 rbelow sub ulong 0xd800 0x800 1238 c3 = add 0xe000 rbelow sub ulong 0x10000 0xe000 1239 c4 = add 0x10000 rbelow sub ulong 0x110000 0x10000 1240 u8app pick5 rbelow 5 c0 c1 c2 c3 c4 1241 end 1242 la = get gl 0 1243 if gt la 0 1244 if lt rrand T50 1245 v = uchar rbelow 256 1246 put ga rbelow la v 1247 end 1248 end 1249 la = get gl 0 1250 if gt la 0 1251 if lt rrand T20 1252 put gl 0 rbelow la 1253 end 1254 end 1255 u8case 1256 end 1257 1258 fn secu8r to void 1259 for t ulong 20000 1260 u8mix 1261 end 1262 for i ulong 100000 1263 put ga mul i 2 0xc3 1264 put ga add mul i 2 1 0xa9 1265 end 1266 put ga 200000 0xed 1267 put ga 200001 0xa0 1268 put ga 200002 0x80 1269 put gl 0 200003 1270 u8case 1271 end 1272 1273 fn secdec to void 1274 for a ulong 256 1275 put ga 0 uchar a 1276 put gl 0 1 1277 deccase 1278 put gl 0 2 1279 for b ulong 256 1280 put ga 1 uchar b 1281 deccase 1282 end 1283 end 1284 put gl 0 3 1285 for i ulong 5 1286 lead = uchar 0xe0 1287 if eq i 1 1288 lead = 0xe1 1289 end 1290 if eq i 2 1291 lead = 0xe8 1292 end 1293 if eq i 3 1294 lead = 0xed 1295 end 1296 if eq i 4 1297 lead = 0xef 1298 end 1299 for b3 ulong 256 1300 for c3 ulong 256 1301 put ga 0 lead 1302 put ga 1 uchar b3 1303 put ga 2 uchar c3 1304 deccase 1305 end 1306 end 1307 end 1308 put gl 0 5 1309 for a4 ulong 8 1310 for b4 ulong 64 1311 for c4 ulong 9 1312 for e4 ulong 9 1313 put ga 0 uchar add 0xf0 a4 1314 put ga 1 uchar add 0x80 b4 1315 put ga 2 third c4 1316 put ga 3 third e4 1317 put ga 4 120 1318 deccase 1319 end 1320 end 1321 end 1322 end 1323 end 1324 1325 fn secdecr to void 1326 for t ulong 20000 1327 put gl 0 0 1328 n = add 1 rbelow 2 1329 for i ulong n 1330 cp = rbelow 0x110000 1331 if or lt cp 0xd800 gt cp 0xdfff 1332 u8app cp 1333 end 1334 end 1335 if eq get gl 0 0 1336 put ga 0 97 1337 put gl 0 1 1338 end 1339 put gl 0 add 1 rbelow get gl 0 1340 deccase 1341 end 1342 end 1343 1344 fn edgecp i ulong to ulong 1345 if eq i 0 1346 ret 0 1347 end 1348 if eq i 1 1349 ret 0x7f 1350 end 1351 if eq i 2 1352 ret 0x80 1353 end 1354 if eq i 3 1355 ret 0x7ff 1356 end 1357 if eq i 4 1358 ret 0x800 1359 end 1360 if eq i 5 1361 ret 0xffff 1362 end 1363 if eq i 6 1364 ret 0x10000 1365 end 1366 if eq i 7 1367 ret 0x10ffff 1368 end 1369 if eq i 8 1370 ret 0x110000 1371 end 1372 if eq i 9 1373 ret 0x100000000 1374 end 1375 ret 0xffffffffffffffff 1376 end 1377 1378 fn secenc to void 1379 for i ulong 11 1380 enccase edgecp i 4 1381 end 1382 for j ulong sub ulong 0xe100 0xd700 1383 enccase add 0xd700 j 4 1384 end 1385 cp = ulong 0 1386 while lt cp 0x110000 bound `1000000` 1387 enccase cp 4 1388 cp = add cp 7 1389 end 1390 for k ulong 11 1391 for cap ulong 5 1392 enccase edgecp k cap 1393 end 1394 end 1395 end 1396 1397 fn main to int 1398 ck eq argcnt 2 1399 n = argread 1 od 0 4000 1400 ck gt n 0 1401 put odn 0 ulong n 1402 mtseed 1403 seccmp 1404 secbig 1405 secfind 1406 sechay 1407 secsplit 1408 secedge 1409 secbyte 1410 secprnd 1411 secfmt 1412 secu8 1413 secu8r 1414 secdec 1415 secdecr 1416 secenc 1417 flush 1418 put wfd 0 2 1419 wtx tfiles 1420 wnum get nf 0 1421 wb1 10 1422 wflush 1423 ret 0 1424 end