Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <time.h>
- #include <math.h>
- /*
- Premise: This program can be built cross platform, to support generation
- of the system 69 factory passcodes to be provided to technicians for a
- predefined date of service operations. Where our hosts are in remote locations,
- and internet / cellular connectivity may not be available. Service techs
- may build the code to run on a predefined service day, which a code will
- be generated. No other day codes are provided, and the program will not
- generate a code for any day other than the allowed day.
- --Service Techs generate the binary to provide to remote techs using an internal code generator
- --Remote Techs download the binary provided to access the factory configuration page, for the specified service day.
- Manual Compilation:
- Linux: $gcc -O2 -Wall -Wextra -s -DALLOWED_YEAR=2025 -DALLOWED_MONTH=12 -DALLOWED_DAY=19 day.c -lm -o day
- MsOS: $x86_64-w64-mingw32-gcc -O2 -Wall -Wextra -s -DALLOWED_YEAR=2025 -DALLOWED_MONTH=12 -DALLOWED_DAY=19 -lm day.c -o day
- */
- #ifndef ALLOWED_YEAR
- #error "ALLOWED_YEAR must be defined at compile time"
- #endif
- #ifndef ALLOWED_MONTH
- #error "ALLOWED_MONTH must be defined at compile time"
- #endif
- #ifndef ALLOWED_DAY
- #error "ALLOWED_DAY must be defined at compile time"
- #endif
- static void get_local_time(struct tm *out){
- time_t now = time(NULL);
- #if defined(_WIN32)
- localtime_s(out, &now);
- #else
- localtime_r(&now, out);
- #endif
- }
- static int date_is_allowed(const struct tm *lt){
- return (lt->tm_year + 1900 == ALLOWED_YEAR &&
- lt->tm_mon + 1 == ALLOWED_MONTH &&
- lt->tm_mday == ALLOWED_DAY);
- }
- /* Generate Daily Factory Passcode */
- static int gp(const struct tm *lt){
- int month = lt->tm_mon + 1;
- int day = lt->tm_mday;
- double a = (month + day) * 6.9;
- double sum = log(a);
- return (int)(sum * 420);
- }
- int main(void){
- struct tm lt;
- get_local_time(<);
- if (!date_is_allowed(<)) {
- fprintf(stderr,"This utility is only valid on: %02d-%02d-%04d\n", ALLOWED_DAY, ALLOWED_MONTH, ALLOWED_YEAR);
- return 1;
- }
- printf("Factory Passcode for Today ONLY:\n");
- int pass = gp(<);
- printf("%d\n", pass);
- #if defined(_WIN32)
- printf("\nPress ENTER to exit...");
- fflush(stdout);
- getchar();
- #endif
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment