mardi 2 juillet 2019

Random password generation using macro in C

I'm trying to write a macro to generate random-like string using __TIME__ and __DATE__

I put my first attempt as fully executable code below.

#include <stdio.h>

#define _STRINGIFY(s) #s
#define STRINGIFY(s) _STRINGIFY(s)

#define TF(s, c)    ((s - '0') * 1) + c

#define TFN              STRINGIFY(TF(__TIME__[7],'m')) \
                         STRINGIFY(TF(__TIME__[1],'A')) \
                         STRINGIFY(TF(__TIME__[3],'J')) \
                         STRINGIFY(TF(__TIME__[6],'d')) \
                         STRINGIFY(TF(__TIME__[0],'C')) \
                         STRINGIFY(TF(__DATE__[5],'h')) \
                         STRINGIFY(TF(__TIME__[5],'p')) \
                         STRINGIFY(TF(__DATE__[10],'F'))

int main()
{
    printf("%s", TFN);

    return 0;
}

I would expect that the printf to print something like

kBLeDjrH

but it gives errors.




Aucun commentaire:

Enregistrer un commentaire