Add 2020/kurdyukov1/try.sh + format/typo checks

The try.sh script tries to find md5sum and if it does not succeed it
tries for openssl. If it is openssl it uses the subcommand md5;
otherwise it just uses md5sum. Whatever the case if either is found it
writes the checksum of prog.c to md5.txt and then it uses prog to write
the checksum to prog.md5.txt. Then it uses diff -s on the two. If
neither tool is found it just skips that check.

Format/typo check README.md file.
This commit is contained in:
Cody Boone Ferguson committed 2023-12-22 09:07:00 -08:00
1 parent 057cb9469a
commit 6e08da7f56
3 files changed
+128 -22

No files matched your search

+58 -22
View File
@@ -4,35 +4,55 @@
make
```
There are alternate versions of this entry. See [Alternate
code](#alternate-code) below for more details.
## To use:
```sh
./prog
# input some text
echo text | ./prog
./prog < file
```
### Try:
```sh
echo IOCCC | ./prog
./prog < prog.x86.asm
./prog < prog.x86_64.asm
./try.sh
```
## Alternate code:
An even smaller alternate version of this entry, prog.alt.c, is provided. This code does not contain any headers, nor any workaround for WIN32 based platforms.
There are a number of alternate versions for this program, some in C and some in
assembly.
To compile this alternate version:
The file [prog.alt.c](prog.alt.c) is smaller and does not contain any
headers or any workaround for WIN32 based platforms.
The file [prog.extra.c](prog.extra.c) has a number of layouts including some for
different social media profile covers as well as different shapes.
The files [prog.x86_64.asm](prog.x86_64.asm) and [prog.x86.asm](prog.x86.asm)
are the program in assembly for x86_64 linux and x86 linux respectively.
### Alternate build:
To build [prog.alt.c](prog.alt.c):
```sh
make alt
```
### Alternate use:
Use `prog.alt` as you would `prog` above.
@@ -47,35 +67,51 @@ You should get a-round-to-it figuring it out!
### MD5 with integers
Just a tiny MD5 checksum utility. Prints hash string of data from stdin.
Work same as `(openssl md5 | cut -d' ' -f2)` command.
Just a tiny MD5 checksum utility. Prints hash string of data from `stdin`.
Works the same as `openssl md5 | cut -d' ' -f2` command.
### My objectives
1. reduce code size as much as possible
2. avoid warnings from GCC/CLANG `-Wall -Wextra -pedantic`
3. portable (regardless of register size and endianness)
4. fit code in a round shape
5. no macro defines
6. no floating-point arithmetics
1. Reduce code size as much as possible.
2. Avoid warnings from gcc/clang `-Wall -Wextra -pedantic`.
3. Portable (regardless of register size and endianness).
4. Fit code in a round shape.
5. Mo macro defines.
6. No floating-point arithmetics.
### Notes
The main difficulty of making MD5 code smaller is a 64x4 bytes long table with constants. Which will take more than 512 bytes in text hex encoding. This table is a results of a sine function, so can be generated dynamically, but merging floating-point arithmetics with precise integer calculations is not a great idea, because can make portability issues.
The main difficulty of making MD5 code smaller is a 64x4 bytes long table with
constants which will take more than 512 bytes in hex encoding. This table is a
results of a sine function, so can be generated dynamically, but merging
floating-point arithmetics with precise integer calculations is not a great
idea, because it can cause portability issues.
Attempts to satisfy CLANG `-Weverything` will ruin comma magic, that is so great for obfuscation, so I don't want to care about that.
Attempts to satisfy `clang -Weverything` will ruin comma magic, that is so great
for obfuscation, so I don't want to care about that.
Probably, should work correctly on any machines, but I have nothing exotic (like BE or not 32/64) to try it.
Probably, should work correctly on any machines, but I have nothing exotic (like
BE or not 32/64) to try it.
Added a macro hack to make `stdin` work in binary mode under Windows (tested
under mingw64), otherwise the hashes can be incorrect.
Added a macro hack to make stdin work in binary mode under Windows (tested under mingw64), otherwise the hashes can be incorrect.
### Bonus
- `prog.extra.c` the same with the sine function (so smaller), and in different shapes.
- [prog.extra.c](prog.extra.c) is the same with the sine function (so smaller),
and in different shapes.
- `prog.x86_64.asm` contains same program, but written on assembly for x86_64 Linux, for the sake of less executable size. Which is 500 bytes long (where 120 is for ELF headers) after compilation. Algorithm details is slightly differ (like constants packing), just to make smaller binary code. It's interesting to compare density of binary code and obfuscated C.
- [prog.x86_64.asm](prog.x86_64.asm) contains the same program, but written in
assembly for x86_64 Linux, for the sake of smaller executable size which is 500
bytes long (where 120 is for the ELF headers) after compilation. Algorithm
details is slightly different (like constants packing), just to make smaller
binary code. It's interesting to compare density of binary code and obfuscated
C.
- `prog.x86.asm` and for x86, although the headers are smaller, but the binary code is larger due to fewer registers and lack of 64-bit multiply.
- [prog.x86.asm](prog.x86.asm) is for x86, although the headers are smaller, but
the binary code is larger due to fewer registers and lack of 64-bit multiply.
## Copyright and CC BY-SA 4.0 License:
+65
View File
@@ -0,0 +1,65 @@
#!/usr/bin/env bash
#
# try.sh - demonstrate IOCCC winner 2020/kurdyukov1
#
# 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
# try and find an md5sum tool
MD5SUM="$(type -P md5sum)"
if [[ -z "$MD5SUM" ]]; then
MD5SUM="$(type -P openssl)"
fi
read -r -n 1 -p "Press any key to run: echo IOCCC | ./prog: "
echo 1>&2
echo IOCCC | ./prog
echo 1>&2
read -r -n 1 -p "Press any key to run: ./prog < prog.c: "
echo 1>&2
./prog < prog.c
echo 1>&2
read -r -n 1 -p "Press any key to run: ./prog < prog: "
echo 1>&2
./prog < prog
echo 1>&2
read -r -n 1 -p "Press any key to run: ./prog < prog.x86.asm: "
echo 1>&2
./prog < prog.x86.asm
echo 1>&2
read -r -n 1 -p "Press any key to run: ./prog < prog.x86_64.asm: "
echo 1>&2
./prog < prog.x86_64.asm
rm -f md5.txt prog.md5.txt
if [[ -n "$MD5SUM" ]]; then
if [[ "$(basename $MD5SUM)" == "openssl" ]]; then
echo "$ $MD5SUM md5 prog.c | cut -f 2 -d' ' > md5.txt" 1>&2
"$MD5SUM" md5 prog.c | cut -f 2 -d' ' > md5.txt
echo "$ ./prog < prog.c > prog.md5.txt" 1>&2
./prog < prog.c > prog.md5.txt
else
echo "$ $MD5SUM prog.c | cut -f1 -d' ' > md5.txt" 1>&2
"$MD5SUM" prog.c | cut -f1 -d' ' > md5.txt
echo "$ ./prog < prog.c > prog.md5.txt" 1>&2
./prog < prog.c > prog.md5.txt
fi
read -r -n 1 -p "Press any key to compare the two files md5.txt and prog.md5.txt: "
echo 1>&2
diff -s md5.txt prog.md5.txt
fi
rm -f md5.txt prog.md5.txt
+5
View File
@@ -4404,6 +4404,11 @@ and tells them they will have to play the WAV files manually. Otherwise it'll
use the program to play the WAV files (and in one case `stdout`).
## <a name="2020_kurdyukov1"></a>[2020/kurdyukov1](/2020/kurdyukov1/prog.c) ([README.md](/2020/kurdyukov1/README.md))
[Cody](#cody) added the [try.sh](/2020/kurdyukov1/try.sh) script.
## <a name="2020_kurdyukov2"></a>[2020/kurdyukov2](/2020/kurdyukov2/prog.c) ([README.md](/2020/kurdyukov2/README.md))
[Cody](#cody) added `-L`/`-I` paths to the Makefile to let this compile more easily if