From d932d86e3798f84a411d8a866fa220b786805765 Mon Sep 17 00:00:00 2001 From: Rutger van Bergen Date: Wed, 22 Dec 2021 18:18:15 +0100 Subject: [PATCH] Don't put password unless requested Also refactored handling of options a little bit. --- minsk.c | 57 +++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 37 insertions(+), 20 deletions(-) diff --git a/minsk.c b/minsk.c index 51d91b2..3f82b64 100644 --- a/minsk.c +++ b/minsk.c @@ -37,6 +37,7 @@ static void (*error_hook)(char *msg); // Minsk-2 has 37-bit words in sign-magnitude representation (bit 36 = sign) typedef unsigned long long int word; +#define MEM_SIZE 4096 #define WORD_MASK 01777777777777ULL #define SIGN_MASK 01000000000000ULL #define VAL_MASK 00777777777777ULL @@ -1245,36 +1246,48 @@ static void setproctitle_init(int argc UNUSED, char **argv UNUSED) #endif -static void init_memory(void) +static void init_memory(int set_password) { - // For the contest, we fill the whole memory with -00 00 0000 0000 (HALT), - // not +00 00 0000 0000 (NOP). Otherwise, an empty program would reveal - // the location of the password :) - for (int i=0; i<4096; i++) - mem[i] = 01000000000000ULL; - - // Store the password - int pos = 02655; - mem[pos++] = 0574060565373; - mem[pos++] = 0371741405340; - mem[pos++] = 0534051524017; + if (set_password) + { + // For the contest, we fill the whole memory with -00 00 0000 0000 (HALT), + // not +00 00 0000 0000 (NOP). Otherwise, an empty program would reveal + // the location of the password :) + for (int i=0; i