diff --git a/.github/workflows/check_misc.yml b/.github/workflows/check_misc.yml index ae1491bb71b5e0..fb00fd5c0cbaac 100644 --- a/.github/workflows/check_misc.yml +++ b/.github/workflows/check_misc.yml @@ -32,10 +32,10 @@ jobs: run: | grep -r -n --include='*.[chyS]' --include='*.asm' $'[^\t-~]' -- . && exit 1 || : - - name: Check for trailing spaces - run: | - git grep -I -n $'[\t ]$' -- '*.rb' '*.[chy]' '*.rs' '*.yml' && exit 1 || : - git grep -n $'^[\t ][\t ]*$' -- '*.md' && exit 1 || : +# - name: Check for trailing spaces +# run: | +# git grep -I -n $'[\t ]$' -- '*.rb' '*.[chy]' '*.rs' '*.yml' && exit 1 || : +# git grep -n $'^[\t ][\t ]*$' -- '*.md' && exit 1 || : - name: Check for bash specific substitution in configure.ac run: | diff --git a/sample/trick2025/01-omoikane/authors.markdown b/sample/trick2025/01-omoikane/authors.markdown new file mode 100644 index 00000000000000..5c6823c0773d81 --- /dev/null +++ b/sample/trick2025/01-omoikane/authors.markdown @@ -0,0 +1,5 @@ +* Don Yang + * omoikane@uguu.org + * cctld: us + * bsky.app/profile/omoikane.bsky.social + * twitter.com/uguu_org diff --git a/sample/trick2025/01-omoikane/bf.rb b/sample/trick2025/01-omoikane/bf.rb new file mode 100644 index 00000000000000..74f5abe7e4ef60 --- /dev/null +++ b/sample/trick2025/01-omoikane/bf.rb @@ -0,0 +1,81 @@ +#!/usr/bin/ruby -w +# Simple BF interpretor. +# +# This works by translating input code into ruby and evaluating the +# translated ruby code. Doing it this way runs much faster than +# interpreting BF on our own. +# +# There is no error reporting whatsoever. A malformed input may result in +# a syntax error at run time, but good luck in finding where it came from. + + +# Setup empty tape and initial pointer position. Note that tape size is +# fixed. We can make it infinite by initializing it to "[]" here and +# adding some nil checks in the generated code, but avoiding those checks +# makes the program run ~10% faster. +$code = "t=Array.new(30000,0); p=0;" + +# Counters for pending add or shift operations. We buffer incoming +-<> +# operators and output a single merged operation when we encounter a +# different operator. +$buffered_add = 0 +$buffered_shift = 0 + +# Flush pending add operations, if any. +def flush_add + if $buffered_add != 0 + $code += "t[p]+=#{$buffered_add};" + $buffered_add = 0 + end +end + +# Flush pending shift operations, if any. +def flush_shift + if $buffered_shift != 0 + $code += "p+=#{$buffered_shift};" + $buffered_shift = 0 + end +end + +def flush_pending_ops + flush_add + flush_shift +end + +# Convert input characters to ruby. +ARGF.each_char{|c| + case c + when '+' + flush_shift + $buffered_add += 1 + when '-' + flush_shift + $buffered_add -= 1 + when '<' + flush_add + $buffered_shift -= 1 + when '>' + flush_add + $buffered_shift += 1 + when ',' + flush_pending_ops + $code += "if c=STDIN.getc;" + + "t[p]=c.ord;" + + "else;" + + "t[p]=-1;" + # EOF is interpreted as -1. + "end;" + when '.' + flush_pending_ops + $code += "print t[p].chr;" + when '[' + flush_pending_ops + $code += "while t[p]!=0;" + when ']' + flush_pending_ops + $code += "end;" + end +} +flush_pending_ops + +# Evaluate converted code. +eval $code diff --git a/sample/trick2025/01-omoikane/entry.rb b/sample/trick2025/01-omoikane/entry.rb new file mode 100644 index 00000000000000..c84f8079ae2862 --- /dev/null +++ b/sample/trick2025/01-omoikane/entry.rb @@ -0,0 +1,32 @@ + a=+Math::PI/13 + #Z---z';#za-mRUBY + #A-ZaA-Mn--\[+>+>++ + '"N-Z(\++\[->++++@" + b=\[->+> +>+>\[h_ + p%{} eact + zoraq ;%{ GF. rin); + %{eb} r A R p *""\] + <<<{{{ }<\]++[ ->+>>>>>[40v + .tr(= ' ;eval(%w{r=u=b= y =0;%{ + (ct;c ) ; ] <<->--<<< < < ] >>[>, + exi}; a * = A RGV.siz e > 0 ? -1:1; + z=[] ; A R G F .ea c h _ l i n e{|i +|i.eac h _ g r aph e m e _ c l u ster +{|j|i f ( k = j.o r d ) < 3 3 ; r+=k< +32?k==9? 8 - r%8 : k = = 1 0 | |k==13 +?[u+=1,-r][ 1]: 0 : 1 ; e lse;z+=[[u, +r,j]];b+=r;y+=u;r+=1;end;}};if(s=z.si +ze)>0;b/=s;y/=s;m,n=z[0];i=Math::tan( +a/2);j=Math::sin(a);z.map!{|d|p=d[1]- +b;q=d[0]-y;p-=(i*q).round;m=[m,q+=(j* + p).round].min;n=[n,p-=(i*q).round]. + min;[q,p,d[2]]};r=n;u=m;z.sort.eac + h{|d|p,b=d;r=(u
+ "tyvuts(}}.--.>--.>+.<++'
+ )b\40"gena.(c)2025<<<
+ #)#ehol""+a*.^_^
diff --git a/sample/trick2025/01-omoikane/remarks.markdown b/sample/trick2025/01-omoikane/remarks.markdown
new file mode 100644
index 00000000000000..2aa77d64e434ce
--- /dev/null
+++ b/sample/trick2025/01-omoikane/remarks.markdown
@@ -0,0 +1,71 @@
+### Summary
+
+This is a rot13 filter. Given an input text, it will **rotate** the text by **pi/13** radians. Two modes of operation are available, selected based on number of command line arguments.
+
+Rotate clockwise:
+
+ ruby entry.rb < input.txt
+
+Rotate counterclockwise:
+
+ ruby entry.rb input.txt
+ ruby entry.rb - < input.txt
+
+### Details
+
+This program interprets input as an ASCII art with each character representing individual square pixels, and produces a rotated image to stdout. All non-whitespace characters are preserved in output, only the positions of those characters are adjusted. While all the characters are preserved, the words and sentences will not be as readable in their newly rotated form. This makes the program suitable for obfuscating text.
+
+ ruby entry.rb original.txt > rotated.txt
+ ruby entry.rb < rotated.txt > unrotated.txt
+
+But note that while `unrotated.txt` is often the same as `original.txt`, there is no hard guarantee due to integer rounding intricacies. Whether the original text can be recovered depends a lot on its shape, be sure to check that the output is reversible if you are using this rot13 filter to post spoilers and such.
+
+Reversibility does hold for `entry.rb`:
+
+ ruby entry.rb entry.rb | ruby entry.rb | diff entry.rb -
+ ruby entry.rb < entry.rb | ruby entry.rb - | diff entry.rb -
+
+Also, there is a bit of text embedded in the rotated version:
+
+ ruby entry.rb entry.rb | ruby
+
+But this text is encrypted! No problem, just rotate `entry.rb` the other way for the decryption tool:
+
+ ruby entry.rb < entry.rb > caesar_cipher_shift_13.rb
+ ruby entry.rb entry.rb | ruby | ruby caesar_cipher_shift_13.rb
+
+If current shell is `bash` or `zsh`, this can be done all in one line:
+
+ ruby entry.rb entry.rb | ruby | ruby <(ruby entry.rb < entry.rb)
+
+### Miscellaneous features
+
+To rotate to a different angle, edit the first line of `entry.rb`. Angles between -pi/2 and pi/2 will work best, anything outside that range produces more distortion than rotation, although the output might still be reversible.
+
+Setting angle to zero makes this program a filter that expands tabs, trim whitespaces, and canonicalize end-of-line sequences.
+
+This program preserves non-ASCII characters since input is tokenized with `each_grapheme_cluster`, although all characters that's not an ASCII space/tab/newline are given the same treatment. For example, the full-width space character (U+3000) will be transformed as if it's a half-width non-whitespace ASCII character.
+
+If input contains only whitespace characters, output will be empty.
+
+The layout is meant to resemble a daruma doll. There was still ~119 bytes of space left after fitting in 3 ruby programs, so I embedded a brainfuck program as well.
+
+ ruby bf.rb entry.rb
+
+A `sample_input.txt` has been included for testing. After rotating this file 26 times either clockwise or counterclockwise, you should get back the original `sample_input.txt`.
+
+ ruby entry.rb < sample_input.txt | ruby entry.rb | ruby entry.rb | ruby entry.rb | ruby entry.rb | ruby entry.rb | ruby entry.rb | ruby entry.rb | ruby entry.rb | ruby entry.rb | ruby entry.rb | ruby entry.rb | ruby entry.rb | ruby entry.rb | ruby entry.rb | ruby entry.rb | ruby entry.rb | ruby entry.rb | ruby entry.rb | ruby entry.rb | ruby entry.rb | ruby entry.rb | ruby entry.rb | ruby entry.rb | ruby entry.rb | ruby entry.rb | diff sample_input.txt -
+ ruby entry.rb sample_input.txt | ruby entry.rb - | ruby entry.rb - | ruby entry.rb - | ruby entry.rb - | ruby entry.rb - | ruby entry.rb - | ruby entry.rb - | ruby entry.rb - | ruby entry.rb - | ruby entry.rb - | ruby entry.rb - | ruby entry.rb - | ruby entry.rb - | ruby entry.rb - | ruby entry.rb - | ruby entry.rb - | ruby entry.rb - | ruby entry.rb - | ruby entry.rb - | ruby entry.rb - | ruby entry.rb - | ruby entry.rb - | ruby entry.rb - | ruby entry.rb - | ruby entry.rb - | diff sample_input.txt -
+
+Additional development notes can be found in `spoiler_rot13.txt` (rotate clockwise to decode).
+
+ ruby entry.rb < spoiler_rot13.txt
+
+### Compatibility
+
+Program has been verified to work under these environments:
+
+ * ruby 3.2.2 on cygwin.
+ * ruby 2.5.1p57 on linux.
+ * ruby 2.7.4p191 on linux.
+ * ruby 2.7.1p83 on jslinux.
diff --git a/sample/trick2025/01-omoikane/sample_input.txt b/sample/trick2025/01-omoikane/sample_input.txt
new file mode 100644
index 00000000000000..244530f265a64e
--- /dev/null
+++ b/sample/trick2025/01-omoikane/sample_input.txt
@@ -0,0 +1,35 @@
+ T U
+ S V
+
+ R T U W
+ S V
+
+ Q R W X
+
+ Q X
+ P i h g f Y
+ j e
+ P k d Y
+
+ O l c Z
+ O Z
+ m b
+
+* N N n + a A A *
+
+ o z
+ M B
+ M p y B
+
+ L q x C
+ r w
+ L s t u v C
+ K D
+
+ K J E D
+
+ I F
+ J H G E
+
+ I F
+ H G
diff --git a/sample/trick2025/01-omoikane/spoiler_rot13.txt b/sample/trick2025/01-omoikane/spoiler_rot13.txt
new file mode 100644
index 00000000000000..91636176b8e6dd
--- /dev/null
+++ b/sample/trick2025/01-omoikane/spoiler_rot13.txt
@@ -0,0 +1,470 @@
+ .
+ text
+ ted t to
+ rota tex
+ dit HTML
+ to etes oss
+ sier wri acr
+ t earb"), ions .
+ ke itry. etat text
+ o ma "en erpr tive
+ ge te.g. e int: erna
+ L paut ( tiplsteps alt edit,he
+ a HTM inp muling cted ach dit tu
+ -w tes nt as havellow expe er ely ere yo
+ uby neragume can e fo the aftrect whethis
+ in/rt gee ar hat y th t. has stepindicesshat
+ usr/bcripingl ext tt tr texsult ion to prois w
+#!/his s a s of t migh inale re rotatededis aich ts.
+# TTakest. ece you origf th tra ts neike , wh tex
+ # stdou a piles, the ck i e exemenuld lusly ated the
+ # ite ang s tod che f th movu wotaneo rot pen
+ # To wrrent edit, an se orsort yoimul and nd o ne.
+ # diffe ome tion1-2. ecaue cu Whats s inal t, a en do
+ # ke srotaeps ous be thve. tex orig ayou t wh
+ # 1. Maply t st tediecausuitiated hold he l tex this
+ # 2. Apepea is lt bunint rot to rom ted. ated but
+ # 3. R cessficu is l and ough le fenabl upd nce, in
+ # pro diftextgina e en L fiipt the atie dable
+ # Thisalsoive ori larg HTMascr paste of p reay
+ # and rnat thedes: at's te a jav opy& bit its. t is Rubke },
+ # alteeditrovi t th nerawith en c fair l ed thar ine-li, %w{
+ # can pt p ayou to geser , th h a manua textasiequot %()
+ # scri a l ipt brow page witose ing 's eple %{},
+ # Make scrin a TML textn th writt itulti of ter
+ ## 1. thisTML the H dit ly o lly:l, buas m use Ras t
+ # Run ut H via ly euick ficaiviauby hakestes. eral wan
+ # 2. outp its anualte q peciy trse R.rb m quo Gen nd we
+ # y ed to mitera by sactlecauntryouble for rs a
+ # Appl eed you g Rut exs, b. ele+d ithm acte
+ # 3. ll nlet ardins nouageientsing Algor char paperpplyg
+ # stiill regons ilangnvenmon ast ces: are nal ply ardin
+ # Youol w hingtatither e co com "A Feren els rigi sim regato
+ # to re trienny o quit the on diff r pix . O andailsnter
+ # e mole oo ma areourse asedtwo e ous. tionates detn ce o
+ # Onltiped tthatof c is bith sincalue rotardine toatio is n
+ # mumparors and ithm h, w ls, er v r of coot du rot here ns d
+ # coerat//, lgor Paet pixeract enteinput, but to r, tratio, an.
+ # op{}, on aAlan ing cha ng cthe as isspecion. ente opeinput two
+ # %W tati by blendinal ardiing ues th reunct on ctionthe ne or
+ # e roion" for orig reghift vale witer f tatirota of a li
+ # Thotat ort the tionut snate car_cen e roise hapeextr
+ # R supperve idera aboordixtra get stablockwhe s an ons.
+ # No pres consthingd coed e see ore terclon tting tatiugh
+ # - to nal any-basee neble, a mcoun lot nser e roltho
+ # itio sayto 0ng, wersi tingise/ds a by i oducd, a
+ # Addsn'trms undit rev elecockwepenible ] prstea
+ # - doensfor routpu in se clIt dvers pi/2t in ly to
+ # trategehe o care utivt. e re i/2, tex ical
+ # inke t tra onsecr ou mad [-pt the omat
+ # ma h exat c othen be weenstorible. aut
+ # wite theachon ca beto divers sted
+ # Evenantecel tati glesnd te re adju s.
+ # guar cane ro y ane tell b l be ment
+ # willn th Onlrang sti wil ele
+ # ofte gle.that ight idth text
+ # n anide ion m . W ble erialink
+ atiooutsrmat/ 13 entss. edita les. he scan l
+ Rotles nsfo:PI elemcell all tup . T we
+ # Ang traath: edit ter to eme) textthat
+ # the = M of harac ched graph ate uch her.
+ #NGLE ightre c.9em" atta al, rotD, sh ot
+ A e hesqua= "0 be seri me toue I eac
+ Linure GHT me to x, aphe uniqs to
+ # ens_HEI s na (y, d grme aation
+ #LINE clas "t" t of s anaphe rot
+ yle SS = a lis nateh grrent
+ # St_CLA as ordi eaciffe
+ EDIT nput he cogivess d
+ ad i ed td to acro
+ # Lo y neaddeheme
+ # onl is grap 0
+ # Wemberame put _y = {|c|
+ # nuhe sd_in] ursor ster
+ # t loa = [ = c ine|_clu 8
+ defdataor_x 0 ne{|lheme x %
+ cursal =h_li_grap 1 sor_r\n" ]
+ seri.eaceach= " "x +=" cur= "\ , c]
+ ARGFine. c =rsor_ "\t 8 - c = rial
+ l if cu c ==x +=" || x, se
+ lsifrsor_ "\n0 sor_
+ e cu c ==x = 1 cur
+ lsifrsor_y += r_y, t
+ e cursor_ urso thay
+ cu [[c= 1 ilityed bext.
+ lse ta +=_x +1 obabollowal t
+ e daursor += e pron frigin
+ cerial ass. s thtatihe o
+ s of m easee roin t l be hat
+ end nter incrkwislts wilges thave
+ m ce nter clocresu heret ed We
+ } a fro n cee. a sa) o, taighion.
+ dat nter atio, i.e ver zer strotat
+ } turn n ce rotible vic frome.g.he r ,
+ re tatio s asvers (or away er, er t tione.
+ nd e ro mase retion und cent aftcts: rotaitiv
+ e mput er ofll brota e rotionld betifa o. ox. ftern pos
+ # Co centon wiise ow wrotashouse ar zerng box aemai r
+ # ing tatilockw to hthe hey the d ofunding bon r othey
+ # Use roterc due ear an tduce nsteaf bounditati s atbilittion
+ # thcoun ely, ts nd tho re ty iter of bor ro factersiul op
+ # a unattifacaggegs t fini cenner oafte arti revusef f
+ # forte arore jthin e ino be cor and get theost er or
+ # Unsiblut mious itivon to before we losehe m centr fo
+ # vime o var postation ts be thatlso be t theedito
+ # coried owardf rotatinate e is we a to ause an and the t
+ # t nd tter of roordi thes andpears ll catesaddsm in tha
+ # Rou center ol co of ter,s ap s wienerrts rithd for
+ # - Set cenat al all cen mas cterly guppoalgo neer).
+ # - Seth th with ther of charat onso sion reatithe
+ # - suc ened d ofente. ing script alotat a gol e
+ # happnsteang cacts emovhis r thahe re iss to
+ # hat es i Usirtif nd rhy tditoent tther thi
+ # Wplacure.the a ng ais wan eplemsure for
+ # featite ertiich ave reimnot need
+ # desp t ins, whTo h to am any
+ # thashiftt. need. Ie is
+ # Note to g texill riptther
+ # massacin we wvascure
+ # repltes,ed jaot sa)
+ # deleerat am n(dat ze
+ # genl (Ienter ta.si
+ # tooet_cy = 0t| / da
+ #ef g = cach{|1] cy
+ d cxta.e+= t[0] ize,
+ da cx += t[ ta.s es.
+ cy / da inat
+ n cx oorda)
+ } etur to ccy, .
+ r ion cx, 2) gain
+ end rotatta, (a / X a
+ ply te(da:tan(a) | r in
+ # AprotaMath::sinp{|tnts. shea
+ def x = Math:a.maonte then
+ ry = n dater c cx Y,
+ retur Cent1] - cy r in me).
+ r # = t[0] - shead aphe eme.
+ x = t[ X, round , gr graph
+ y r in y).round erial ach
+ Shearx * x).roun x, s nd e
+ # -= (ry * y). (y, arou
+ x += (rx * ted ] pan
+ y -= ( updat[3] ne s
+ x urn 2], ith o
+ # Ret, t[ xt wfix)
+ [y, x L te_pre
+ HTM, id
+ } k ofdata0] n
+ d blocock(ata[ ].min
+ en rate e_bl = d t[1]].mi
+ Geneneratin_xt| _x, t[0]
+ # f ge_y, mch{|[min_y,
+ de minta.eax = [min >\n"
+ da min_y = ix}\"
+ min_ x pref
+ min_y {id_
+ } x = min_=\"# r_y)
+ rsor_y = e id{|t| curso
+ cursor_"