Thanks to visit codestin.com
Credit goes to github.com

Skip to content

sample/trick2025/: adds the top-five entries of TRICK 2025 #13122

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/check_misc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
5 changes: 5 additions & 0 deletions sample/trick2025/01-omoikane/authors.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
* Don Yang
* [email protected]
* cctld: us
* bsky.app/profile/omoikane.bsky.social
* twitter.com/uguu_org
81 changes: 81 additions & 0 deletions sample/trick2025/01-omoikane/bf.rb
Original file line number Diff line number Diff line change
@@ -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
32 changes: 32 additions & 0 deletions sample/trick2025/01-omoikane/entry.rb
Original file line number Diff line number Diff line change
@@ -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 *""\]
<<<{{{ }<\]<b
]<l(%w| } ; a;a=%Y/
evar{|c)} <][ #pgny\W{f
chaa,b)]>++[ ->+>>>>>[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<p)?n:r;print"\n"
*(p-u),"\40"*(b-r),d[2];u=p;r=
b+1};print"\n";end}*"");%(]>
"tyvuts(}}.--.>--.>+.<++'
)b\40"gena.(c)2025<<<
#)#ehol""+a*.^_^
71 changes: 71 additions & 0 deletions sample/trick2025/01-omoikane/remarks.markdown
Original file line number Diff line number Diff line change
@@ -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.
35 changes: 35 additions & 0 deletions sample/trick2025/01-omoikane/sample_input.txt
Original file line number Diff line number Diff line change
@@ -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
Loading
Loading