j0h

RemoteFactoryPassCode

j0h
Dec 19th, 2025 (edited)
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.41 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <time.h>
  3. #include <math.h>
  4. /*
  5.    Premise: This program can be built cross platform, to support generation
  6.     of the system 69 factory passcodes to be provided to technicians for a
  7.     predefined date of service operations. Where our hosts are in remote locations,
  8.     and internet / cellular connectivity may not be available. Service techs
  9.     may build the code to run on a predefined service day, which a code will
  10.     be generated. No other day codes are provided, and the program will not
  11.     generate a code for any day other than the allowed day.
  12.    
  13.     --Service Techs generate the binary to provide to remote techs using an internal code generator
  14.    
  15.     --Remote Techs download the binary provided to access the factory configuration page, for the specified service day.  
  16.    
  17.    Manual Compilation:
  18.    Linux: $gcc -O2 -Wall -Wextra -s -DALLOWED_YEAR=2025 -DALLOWED_MONTH=12 -DALLOWED_DAY=19 day.c -lm -o day
  19.    MsOS:  $x86_64-w64-mingw32-gcc -O2 -Wall -Wextra -s -DALLOWED_YEAR=2025 -DALLOWED_MONTH=12 -DALLOWED_DAY=19 -lm day.c -o day
  20.    
  21. */
  22.  
  23.     #ifndef ALLOWED_YEAR
  24.     #error "ALLOWED_YEAR must be defined at compile time"
  25.     #endif
  26.     #ifndef ALLOWED_MONTH
  27.     #error "ALLOWED_MONTH must be defined at compile time"
  28.     #endif
  29.     #ifndef ALLOWED_DAY
  30.     #error "ALLOWED_DAY must be defined at compile time"
  31.     #endif
  32.  
  33. static void get_local_time(struct tm *out){
  34.     time_t now = time(NULL);
  35.     #if defined(_WIN32)
  36.         localtime_s(out, &now);
  37.     #else
  38.         localtime_r(&now, out);
  39.     #endif
  40. }
  41.  
  42. static int date_is_allowed(const struct tm *lt){
  43.     return (lt->tm_year + 1900 == ALLOWED_YEAR &&
  44.             lt->tm_mon + 1     == ALLOWED_MONTH &&
  45.             lt->tm_mday        == ALLOWED_DAY);
  46. }
  47.  
  48. /* Generate Daily Factory Passcode  */
  49. static int gp(const struct tm *lt){
  50.     int month = lt->tm_mon + 1;
  51.     int day   = lt->tm_mday;
  52.  
  53.     double a   = (month + day) * 6.9;
  54.     double sum = log(a);
  55.     return (int)(sum * 420);
  56. }
  57.  
  58. int main(void){
  59.     struct tm lt;
  60.     get_local_time(&lt);
  61.  
  62.     if (!date_is_allowed(&lt)) {
  63.         fprintf(stderr,"This utility is only valid on: %02d-%02d-%04d\n", ALLOWED_DAY, ALLOWED_MONTH, ALLOWED_YEAR);
  64.         return 1;
  65.     }
  66.     printf("Factory Passcode for Today ONLY:\n");
  67.     int pass = gp(&lt);
  68.     printf("%d\n", pass);
  69.     #if defined(_WIN32)
  70.         printf("\nPress ENTER to exit...");
  71.         fflush(stdout);
  72.         getchar();
  73.     #endif
  74.     return 0;
  75. }
  76.  
Advertisement
Add Comment
Please, Sign In to add comment