rpass

Strong password generator for humans
git clone git://git.sgregoratto.me/rpass
Log | Files | Refs | README

commit a1553cc74c7c646df407a21ae515773214fde8dc
parent adb288aa4c25cdc7deeee009d06bb012333e3015
Author: Tim Kuijsten <info+git@netsend.nl>
Date:   Fri, 13 Dec 2019 17:28:19 +0100

K&R code style

Diffstat:
Mrpass.c | 85+++++++++++++++++++++++++++++++++++++++++--------------------------------------
1 file changed, 44 insertions(+), 41 deletions(-)

diff --git a/rpass.c b/rpass.c @@ -24,59 +24,62 @@ * unambiguous. */ static const char first[] = "bdfhjklmnprstvwxz"; /* drop c, g, q, y = 4 bpc */ -static const char secon[] = "aeiou"; /* vowels, 2.3 bpc */ -static const char third[] = "fhjklmnprstxz"; /* drop b, c, d, g, q, v, w, y = 3.7 bpc */ +static const char secon[] = "aeiou"; /* vowels, 2.3 bpc */ +static const char third[] = "fhjklmnprstxz"; /* drop b, c, d, g, q, v, w, + * y = 3.7 bpc */ int main(int argc, char **argv) { - int c; - double bits, fbpc, sbpc, tbpc; + double bits, fbpc, sbpc, tbpc; + int c; - while ((c = getopt(argc, argv, "h")) != -1) - switch (c) { - case 'h': - case '?': - fputs("usage: rpass [bitlen]\n", stdout); - exit(0); - default: - fputs("usage: rpass [bitlen]\n", stderr); - exit(1); - } - argc -= optind; - argv += optind; + while ((c = getopt(argc, argv, "h")) != -1) + switch (c) { + case 'h': + case '?': + fputs("usage: rpass [bitlen]\n", stdout); + exit(0); + default: + fputs("usage: rpass [bitlen]\n", stderr); + exit(1); + } - fbpc = log2(sizeof first - 1); - sbpc = log2(sizeof secon - 1); - tbpc = log2(sizeof third - 1); + argc -= optind; + argv += optind; - if (argc) - bits = strtol(argv[0], NULL, 10); - else - bits = 40.0; + fbpc = log2(sizeof first - 1); + sbpc = log2(sizeof secon - 1); + tbpc = log2(sizeof third - 1); - if (bits <= 0) { - fputs("usage: rpass [bitlen]\n", stderr); - exit(1); - } + if (argc) { + bits = strtol(argv[0], NULL, 10); + } else { + bits = 40.0; + } - /* make three letter words */ - c = 0; - while (bits > 0) { - putchar(first[arc4random_uniform(sizeof first - 1)]); - bits -= fbpc; + if (bits <= 0) { + fputs("usage: rpass [bitlen]\n", stderr); + exit(1); + } - putchar(secon[arc4random_uniform(sizeof secon - 1)]); - bits -= sbpc; + /* make three letter words */ + c = 0; + while (bits > 0) { + putchar(first[arc4random_uniform(sizeof first - 1)]); + bits -= fbpc; - putchar(third[arc4random_uniform(sizeof third - 1)]); - bits -= tbpc; + putchar(secon[arc4random_uniform(sizeof secon - 1)]); + bits -= sbpc; - if (bits > 0 && c++ % 2) - putchar(' '); - } + putchar(third[arc4random_uniform(sizeof third - 1)]); + bits -= tbpc; - putchar('\n'); + if (bits > 0 && c++ % 2) + putchar(' '); + } - return 0; + putchar('\n'); + + return 0; }