Generating high entropy secretphrase:
int gen_randomacct(int randchars,char *NXTaddr,char *NXTsecret,char *randfilename)
{
int i,j,x,iter,bitwidth = 6;
FILE *fp;
char buf[512],fname[512];
unsigned char bits[33];
NXTaddr[0] = 0;
randchars /= 8;
if ( randchars > (int)sizeof(bits) )
randchars = (int)sizeof(bits);
if ( randchars < 3 )
randchars = 3;
for (iter=0; iter<=8; iter++)
{
sprintf(fname,"%s.%d",randfilename,iter);
fp = fopen(fname,"rb");
if ( fp == 0 )
{
sprintf(buf,"dd if=/dev/random count=%d bs=1 > %s",randchars*8,fname);
printf("cmd.(%s)\n",buf);
system(buf);
}
fp = fopen(fname,"rb");
if ( fp != 0 )
{
fread(bits,1,sizeof(bits),fp);
for (i=0; i+bitwidth<(sizeof(bits)*8) && i/bitwidth {
for (j=x=0; j<6; j++)
{
if ( GETBIT(bits,i*bitwidth+j) != 0 )
x |= (1 << j);
}
printf("i.%d j.%d x.%d %c\n",i,j,x,1+' '+x);
NXTsecret[randchars*iter + i/bitwidth] = 1+ ' ' + x;
}
NXTsecret[randchars*iter + i/bitwidth] = 0;
fclose(fp);
}
sleep(3);
}
strcpy(NXTaddr,issue_getAccountId(NXTsecret));
printf("NXT.%s NXTsecret.(%s)\n",NXTaddr,NXTsecret);
return(0);
}
This works on Mac and Unix, I am not sure if there is a /dev/random equivalent for Windows
you can specify the number of random chars and a filename where it will save the random bits so it can be reproduced.
Not sure if anybody needs this, but it was a bit tricky to convince my Mac to spit out decent random numbers so I figured it might help someone.
Even without the call to issue_getAccountId, this would be a useful program for people to locally generate a high entropy password
James