From bb1ac2484d36ce8301c54571aa2b86db3d1a5dba Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Thu, 30 Nov 2023 08:39:38 -0800 Subject: [PATCH] Add try.sh and hint.md to 2012/hou + formatting The hint.md file is necessary as the '#' header in it specifies the title and stylesheet as part of the entry. The try.sh script is as usual. Format/typo check README.md file. The hint.md file formatting was not changed due to the regexp engine amongst other reasons. Just obvious spelling errors were updated. --- 2012/hou/README.md | 26 ++++----- 2012/hou/hint.md | 134 ++++++++++++++++++++++++++++++++++++++++++++ 2012/hou/try.sh | 39 +++++++++++++ thanks-for-fixes.md | 9 +++ 4 files changed, 195 insertions(+), 13 deletions(-) create mode 100644 2012/hou/hint.md create mode 100755 2012/hou/try.sh diff --git a/2012/hou/README.md b/2012/hou/README.md index 7ac62dccb..95e2deb9e 100644 --- a/2012/hou/README.md +++ b/2012/hou/README.md @@ -15,22 +15,17 @@ make ### Try: ```sh -less hou.c - -./hou ansi.txt hou.c | less -r - -./hou chk.txt hou.c | wc - -./hou markdown.txt README.md > remarks.htm +./try.sh ``` View the `remarks.htm` file in your web browser. The result is best viewed in a 80x25 console with ANSI colors. + ## Try (Windows): -```sh +``` copy header.htm hou.htm /y hou html.txt hou.c >> hou.htm start hou.htm @@ -65,6 +60,7 @@ The author does not own the original anime series where the embedded ASCII arts come from. For comparison, original non-ASCII art depictions of the relevant characters and objects can be found by googling the embedded text messages. + ### Syntax files The syntax file consists of a number of rewriting rules. Each rule consists of a @@ -81,9 +77,10 @@ The following regular expression operators are supported: () [] * + ? | "" ``` -For example, one can use the following expression to match a certain declaration statement in hou.c: +For example, one can use the following expression to match a certain declaration +statement in [hou.c](hou.c): -``` +```re "char"[ *]*[a-zA-Z_][0-9a-zA-Z_]*[ ]*((=[0-9a-zA-Z_ ]+)|(\[[0-9a-zA-Z_ ]*\]))?[ ]*(,[ *]*[a-zA-Z_][0-9a-zA-Z_]*[ ]*((=[0-9a-zA-Z_ ]+)|(\[[0-9a-zA-Z_ ]*\]))?[ ]*)*; ``` @@ -93,10 +90,11 @@ hang for the competing Perl engine while matching itself. Try to compare these two engines: ```sh - ./hou ansi.txt ansi.txt - perl patho.pl < ansi.txt +./hou ansi.txt ansi.txt +perl patho.pl < ansi.txt ``` + ### Limitations Finally, there are a few limitations... @@ -108,12 +106,13 @@ Finally, there are a few limitations... - Incorrect syntax files are not tolerated. - The program relies on ASCII. + ### Why obfuscated The first layer of obfuscation comes from the challenge of embedding a large ASCII art in a dense blob. The entire art is composed using only keywords, strings and character constants. That results in a number of otherwise useless -defines and quite a number of unconventionally written constants. While the +`#define`s and quite a number of unconventionally written constants. While the preprocessor may remove the former, the later would remain regardless of beautification and preprocessing. @@ -128,6 +127,7 @@ amount of spaghetti branches and virtual thread creations. Finally, the VM in As an extra tweak, the text message actually does something useful. Remove the "Make a contract with me" catch line and the program would cease to function. + ### References [1][Russ Cox, Regular Expression Matching: the Virtual Machine Approach](http://swtch.com/~rsc/regexp/regexp2.html) diff --git a/2012/hou/hint.md b/2012/hou/hint.md new file mode 100644 index 000000000..011634fb9 --- /dev/null +++ b/2012/hou/hint.md @@ -0,0 +1,134 @@ +# Most useful obfuscation + +Qiming Hou + + + + +## Judges' comments: + +### To build: + + make hou + +### To run: + + ./hou syntax-file file-to-process + +### Try (Unix): + +The results are best viewed in a 80x25 console with ANSI colors. + + less hou.c + + ./hou ansi.txt hou.c | less -r + + ./hou chk.txt hou.c | wc + + ./hou markdown.txt remarks.markdown > remarks.htm + your-browser remarks.htm + +### Try (Windows): + + copy header.htm hou.htm /y + hou html.txt hou.c >> hou.htm + start hou.htm + +### Selected Judges Remarks: + +What a versatile entry! It can be used to check the size of IOCCC entries *and* to publish them as HTML. + +For extra credit: what is the meaning of the number 2321237? + + +## Author's comments: + +### Disclaimer + +The reviewer may have already noticed that the 2nd page of this program is a +dense blob, which is discouraged by the contest rules. We wish to point out that +a majority of state-of-art programming editors support syntax highlighting, +which should be enabled when reading this entry. Anticipating that the +reviewer's preferred color setting may produce a suboptimal visual effect, a few +syntax files are provided to highlight the source code under an author-provided +setting, using the submitted program itself. Syntax highlighting would also +visually improve the 3rd page. + +The code may throw a few warnings due to formatting constraints. The author did +try to remove warnings under gcc and Visual Studio, though. + +The author does not own the original anime series where the embedded ASCII arts +come from. For comparison, original non-ASCII art depictions of the relevant +characters and objects can be found by googling the embedded text messages. + + +### Syntax files + +The syntax file consists of a number of rewriting rules. Each rule consists of a +regular expression, a space, a format string, and a newline. All text matching +the regular expression would be replaced by the format string. In case of a +conflict, rules appearing earlier would take precedence. One can refer to the +original text in the format string using "%s". Other "%" characters in the +format string must be escaped with another "%". The space character can be used +in the regular expression by escaping it with [] or "". + +The following regular expression operators are supported: + + () [] * + ? | "" + +For example, one can use the following expression to match a certain declaration statement in hou.c: + + "char"[ *]*[a-zA-Z_][0-9a-zA-Z_]*[ ]*((=[0-9a-zA-Z_ ]+)|(\[[0-9a-zA-Z_ ]*\]))?[ ]*(,[ *]*[a-zA-Z_][0-9a-zA-Z_]*[ ]*((=[0-9a-zA-Z_ ]+)|(\[[0-9a-zA-Z_ ]*\]))?[ ]*)*; + +The regex engine is also algorithmically efficient. To illustrate the point, +ansi.txt contains a pathological expression [2] that guarantees a hang for the +competing Perl engine while matching itself. Try to compare these two engines: + + ./hou ansi.txt ansi.txt + perl patho.pl < ansi.txt + +Finally, there are a few limitations... + + +- The only escape sequence supported is \n and it doesn't work in []. +- The maximum file/rule size is a linear function of the hard-coded constant M. +- Single-character matches at the end of file may be missed. +- The operator | doesn't obey precedence rules and some extra ()s may be required. +- Incorrect syntax files are not tolerated. +- The program relies on ASCII. + +### Why obfuscated + +The first layer of obfuscation comes from the challenge of embedding a large +ASCII art in a dense blob. The entire art is composed using only keywords, +strings and character constants. That results in a number of otherwise useless +defines and quite a number of unconventionally written constants. While the +preprocessor may remove the former, the later would remain regardless of +beautification and preprocessing. + +The second layer of obfuscation comes from the need to squeeze a reasonably +powerful regex engine into the remaining area that isn't occupied by excessive +keywords and useless constants. To achieve this, the regex compiler is written +using the same threaded virtual machine [1] that parses the regex. Due to +compiler limitations, the generated VM code also ends up obscured by a large +amount of spaghetti branches and virtual thread creations. Finally, the VM in +[1] is extended to track multiple expression matches for the actual formatting. + +As an extra tweak, the text message actually does something useful. Remove the +"Make a contract with me" catch line and the program would cease to function. + + +### References + +[1] [Russ Cox, Regular Expression Matching: the Virtual Machine Approach](http://swtch.com/~rsc/regexp/regexp2.html) + +[2] [Regular Expression Matching Can Be Simple And Fast (but is slow in Java, Perl, PHP, Python, Ruby, ...)](http://swtch.com/~rsc/regexp/regexp1.html) + +-------------------------------------------------------------------------------- + diff --git a/2012/hou/try.sh b/2012/hou/try.sh new file mode 100755 index 000000000..f19b41c35 --- /dev/null +++ b/2012/hou/try.sh @@ -0,0 +1,39 @@ +#!/usr/bin/env bash +# +# try.sh - demonstrate IOCCC winner 2012/hou +# + +# make sure CC is set so that when we do make CC="$CC" it isn't empty. Doing it +# this way allows us to have the user specify a different compiler in an easy +# way. +if [[ -z "$CC" ]]; then + CC="cc" +fi + +make CC="$CC" all >/dev/null || exit 1 + +# clear screen after compilation so that only the entry is shown +clear + +read -r -n 1 -p "Press any key to run: less hou.c (space = next page, q = quit): " +echo 1>&2 +less -X hou.c +echo 1>&2 + +read -r -n 1 -p "Press any key to run: ./hou ansi.txt hou.c | less -r (space = next page, q = quit): " +echo 1>&2 +echo "$ ./hou ansi.txt hou.c | less -r" +./hou ansi.txt hou.c | less -r +echo 1>&2 + +read -r -n 1 -p "Press any key to check size of hou.c: " +echo 1>&2 +echo "$ ./hou chk.txt hou.c | wc" 1>&2 +./hou chk.txt hou.c | wc +echo 1>&2 + +read -r -n 1 -p "Press any key to run: ./hou markdown.txt hint.md > remarks.htm: " +echo 1>&2 +./hou markdown.txt hint.md > remarks.htm +echo 1>&2 +echo "Now open remarks.htm in your web browser of choice." diff --git a/thanks-for-fixes.md b/thanks-for-fixes.md index 65d1d914d..4be66e285 100644 --- a/thanks-for-fixes.md +++ b/thanks-for-fixes.md @@ -3344,6 +3344,15 @@ Cody fixed a typo in the ruby script Cody restored the original code from the archive. +## [2012/hou](2012/hou/hou.c) ([README.md](2012/hou/README.md])) + +Cody added the [try.sh](2012/hou/try.sh) script and restored the original [hint +markdown file](2012/hou/hint.md) as the changes made when converting to a GitHub +README.md made the generated html not look correct; it did not have a title, a +stylesheet etc. due to the fact that there is no `#` header (which specified +title and stylesheet) and other formatting changes. + + ## [2012/kang](2012/kang/kang.c) ([README.md](2012/kang/README.md])) Cody added alt code that fixes a problem where in German 'v' sounds like 'f'