proof_christmas_tree.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /**
  2. * proof_christmas_tree.c (prvhash1) version 4.3.3
  3. *
  4. * Program reads certain "prvhash1" data and represents it as two-dimensional
  5. * ASCII-art. Generates HTML to stdout.
  6. *
  7. * License
  8. *
  9. * Copyright (c) 2022 Aleksey Vaneev
  10. *
  11. * Permission is hereby granted, free of charge, to any person obtaining a
  12. * copy of this software and associated documentation files (the "Software"),
  13. * to deal in the Software without restriction, including without limitation
  14. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  15. * and/or sell copies of the Software, and to permit persons to whom the
  16. * Software is furnished to do so, subject to the following conditions:
  17. *
  18. * The above copyright notice and this permission notice shall be included in
  19. * all copies or substantial portions of the Software.
  20. *
  21. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  22. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  23. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  24. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  25. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  26. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  27. * DEALINGS IN THE SOFTWARE.
  28. */
  29. #include <stdio.h>
  30. #include <stdint.h>
  31. #define PH_HASH_COUNT 200
  32. #define READ_MODE 1 // 0 or 1
  33. #define READ_WIDTH ( PH_HASH_COUNT + 1 )
  34. #define READ_HEIGHT ( READ_WIDTH * 32 )
  35. static inline uint8_t prvhash_core1( uint8_t* const Seed,
  36. uint8_t* const lcg, uint8_t* const Hash )
  37. {
  38. *Hash ^= (uint8_t) ( *Seed ^ 0x1 );
  39. *lcg ^= (uint8_t) ( *Seed ^ READ_MODE );
  40. const uint8_t out = (uint8_t) ( *lcg ^ *Seed );
  41. *Seed ^= *Hash;
  42. return( out & 1 );
  43. }
  44. int main()
  45. {
  46. uint8_t Seed = 0, lcg = 0;
  47. uint8_t Hash[ PH_HASH_COUNT ] = { 0 };
  48. int HashPos = 0;
  49. printf( "<html><head>"
  50. "<style>body{font: 1px Courier; line-height: 1px;}</style>\n" );
  51. printf( "</head><body><pre>\n" );
  52. for( int i = 0; i < PH_HASH_COUNT + 2; i++ ) // Remove pixel offset.
  53. {
  54. prvhash_core1( &Seed, &lcg, Hash + HashPos );
  55. if( ++HashPos == PH_HASH_COUNT ) HashPos = 0;
  56. }
  57. for( int l = 0; l < READ_HEIGHT; l++ )
  58. {
  59. for( int k = 0; k < READ_WIDTH; k++ )
  60. {
  61. if( prvhash_core1( &Seed, &lcg, Hash + HashPos ))
  62. printf( "0" );
  63. else
  64. printf( " " );
  65. if( ++HashPos == PH_HASH_COUNT ) HashPos = 0;
  66. }
  67. printf( "\n" );
  68. }
  69. printf( "</pre></body>\n</html>\n" );
  70. }