diff --git a/2012/grothe/README.md b/2012/grothe/README.md index 622221068..6fd9ac298 100644 --- a/2012/grothe/README.md +++ b/2012/grothe/README.md @@ -48,7 +48,7 @@ Had it not been, this entry would have been rejected in round 0. The judges also took some liberty obfuscating this entry a little more. How does this entry work? The only place multiplication is used is -to perform the `atoi()` conversion. +to perform the `atoi(3)` conversion. ## Author's remarks: @@ -57,27 +57,27 @@ to perform the `atoi()` conversion. This program implements a version of [Shamir's Secret Sharing](http://en.wikipedia.org/wiki/Shamir%27s_Secret_Sharing). Shamir's Secret -Sharing allows you to encrypt a file into N parts where it will take M parts to +Sharing allows you to encrypt a file into `N` parts where it will take `M` parts to recreate the original file. E.g. you can split the secret recipe for Crystal Pepsi into 3 parts and require two of them be available to extract the original recipe. Actually surprisingly useful for an IOCCC entry :-) + ### Usage -To share a secret. +To share a secret. For example: -E.g. +- File to share: [cookie_recipe.txt](cookie_recipe.txt). +- Number of pieces: 2 + file to be shared +- Total number of pieces created by program: 4 +- Pieces needed to reassemble recipe: 3 or greater -File to be shared - [cookie_recipe.txt](cookie_recipe.txt). -number of pieces - 2 + file to be shared -total number of pieces created by program 4 -pieces needed to reassemble recipe 3 or greater ### Example usage To split a secret into 4 pieces of which at least 3 will be needed to get it (in -this case a recipe) back: +this case the cookie recipe) back: ```sh ./grothe \ @@ -86,7 +86,7 @@ this case a recipe) back: 1+cookie_piece1.dat 2+cookie_piece2.dat 3+cookie_piece3.dat 4+cookie_piece4.dat ``` -To put recipe back together using the first, second and fourth pieces: +To put the recipe back together using the first, second and fourth pieces: ```sh ./grothe \ @@ -94,6 +94,7 @@ To put recipe back together using the first, second and fourth pieces: +cookie_recipe_restore.txt ``` + ### Limitations The program is limited to 256 input and output files and will slow down @@ -101,34 +102,37 @@ dramatically when you get past 20-50 inputs and outputs. ### Obfuscations -* nothing is done consistently throughout the program E.g `i+=1`, `i=i+1`, `i++` +* Nothing is done consistently throughout the program E.g `i+=1`, `i=i+1`, `i++` and `++i` are all used in the program. The mark of true code buggery: "A foolish consistency is the hobgoblin of little minds." - [Ralph Waldo Emerson](https://en.wikipedia.org/wiki/Ralph_Waldo_Emerson) -* uses the most powerful obfuscation of all "Math". "Any sufficiently advanced +* Uses the most powerful obfuscation of all "Math". "Any sufficiently advanced cryptography is indistinguishable from magic." - Apologies to [Arthur C. Clarke](https://en.wikipedia.org/wiki/Arthur_C._Clarke) -* shadows variables by using brackets in main program to create local copies of +* Shadows variables by using brackets in main program to create local copies of variables that are the same as global scope variables. `-Wshadow` should probably be a part of `-Wall` in gcc. -* uses `array_index[array_name]` instead of `array_name[array_index]` in several +* Uses `array_index[array_name]` instead of `array_name[array_index]` in several places. Still don't know why C continues to allow this (error strings are encoded with offsets that are also used to select them in the case statement. All strings are located in one function for easy localization). -* liberal use of octal numbers, hexadecimal numbers and regular decimal numbers -throughout program. +* Liberal use of octal numbers, hexadecimal numbers and regular decimal numbers +throughout the program. -* variables and function names are semi-random and upper and lower case characters are used -* use of `#define`s from `stdio.h`, `stdlib.h` for values `_STDIO_H` and +* Variables and function names are semi-random and upper and lower case +characters are used. + +* Use of `#define`s from `stdio.h`, `stdlib.h` for values `_STDIO_H` and `EXIT_SUCCESS` used to represent 1 and 0 respectively in the program. -* arrays only need to be 256x256 but most are set to greater values than they +* Arrays only need to be 256x256 but most are set to greater values than they need to be so trying to figure it out can be a bit tough. + ### References * David Madore's implementation of Shamir's Secret Sharing - diff --git a/2012/grothe/cookie_piece1.dat b/2012/grothe/cookie_piece1.dat index d7a702f6c..dd3742e1c 100644 Binary files a/2012/grothe/cookie_piece1.dat and b/2012/grothe/cookie_piece1.dat differ diff --git a/2012/grothe/cookie_piece2.dat b/2012/grothe/cookie_piece2.dat index 7c4ac5ae7..77f68d417 100644 Binary files a/2012/grothe/cookie_piece2.dat and b/2012/grothe/cookie_piece2.dat differ diff --git a/2012/grothe/cookie_piece3.dat b/2012/grothe/cookie_piece3.dat index 097caa32d..b17cd5f59 100644 Binary files a/2012/grothe/cookie_piece3.dat and b/2012/grothe/cookie_piece3.dat differ diff --git a/2012/grothe/cookie_piece4.dat b/2012/grothe/cookie_piece4.dat index 6445cfad2..fd9a4a61d 100644 Binary files a/2012/grothe/cookie_piece4.dat and b/2012/grothe/cookie_piece4.dat differ diff --git a/2012/grothe/cookie_recipe_restore.txt b/2012/grothe/cookie_recipe_restore.txt index 6445cfad2..4a2a786b1 100644 Binary files a/2012/grothe/cookie_recipe_restore.txt and b/2012/grothe/cookie_recipe_restore.txt differ diff --git a/2012/grothe/grothe.c b/2012/grothe/grothe.c index 1d2c651fc..2083aeac3 100644 --- a/2012/grothe/grothe.c +++ b/2012/grothe/grothe.c @@ -15,7 +15,7 @@ n;}}void X(int v,int u){char*y=0;v-=1;switch(v){case(0x2):y ="HckngfVqQrgpKprwv" "Hkng"; BC(4):y="JempihXsStirMrtyxJmpi"; BC(0):y="PointValueTooLarge"; BC 0x1:y= "EvqmjdbufJoqvuQpjou";BC(6):y="TuOtv{zLorky";BC(3):y="WrrPdq|RxwsxwSrlqwv";BC(5) :y="GfiFwlzrjsyX~syf}"; BC(07):y="UvV|{w|{Mpslz";}if(u)exit(0); f(y,v);exit(1);} -int main(int t,const char*T[]){for(i=00;i<0x100;++i)for(j=0;j<=i;++j)if(1==y(i,j +int main(int t, char *T[]){ for (i=00;i<0x100;++i) for (j=0;j<=i;++j)if(1==y(i,j ))W[i]=j,W[j]=i;for(k=0x1;k=toupper('0'))&&(T[k][l] <=tolower('9'));l++){p=p*10+(T[k][l]-'0');if(p>=256)X(1,0);}if(T[k][l]=='-'){for (m=0;m/dev/null || exit 1 + +read -r -n 1 -p "Press any key to break recipe into crumbs: " +echo 1>&2 +echo "$ ./grothe -cookie_recipe.txt 1-/dev/urandom 2-/dev/urandom \\ + 1+cookie_piece1.dat 2+cookie_piece2.dat 3+cookie_piece3.dat 4+cookie_piece4.dat" +echo 1>&2 + +read -r -n 1 -p "Press any key to restore cookie recipe: " +echo 1>&2 +echo "$ ./grothe 1-cookie_piece1.dat 2-cookie_piece2.dat 4-cookie_piece4.dat +cookie_recipe_restore.txt" 1>&2 +echo 1>&2 + +read -r -n 1 -p "Press any key to show that the two files are the same: " +echo 1>&2 +diff -s cookie_recipe.txt cookie_recipe_restore.txt +echo 1>&2 + +read -r -n 1 -p "Press any key to see the recipe file, restored: " +echo 1>&2 +cat cookie_recipe_restore.txt diff --git a/thanks-for-fixes.md b/thanks-for-fixes.md index b85db13be..208b49543 100644 --- a/thanks-for-fixes.md +++ b/thanks-for-fixes.md @@ -3372,7 +3372,14 @@ Cody also fixed a typo in the ruby script ## [2012/grothe](2012/grothe/grothe.c) ([README.md](2012/grothe/README.md)) -[Cody](#cody) restored the original code from the archive. +[Cody](#cody) added the [try.sh](2012/grothe/try.sh) script. + +Cody also changed `argv` to be not `const char **` but `char **`, mostly out of an +abundance of caution in case clang, which already imposes restrictions on the +types of args to `main()` including to do with `char **`, decides to further +restrict them. + +Cody also restored the original code from the archive. ## [2012/hamano](2012/hamano/hamano.c) ([README.md](2012/hamano/README.md]))