To keep the command-line call simple, the set-bits, set-alphabet and set-grouping functions are provided separately, these functions validate the argument and set the actual values for the bits, alphabet and grouping respectively: Each command-line option has an argument which is a string, and the command-line macro allows specifying some processing to be done on that argument. Each of these arguments are optional and the syntax allows specifying a help text for them too, so the script will print out usage information if passed in the -h argument. See the full documentation for the macro for details, however, below is the invocation required to accept three command line arguments -b for the number of bits in the password, -a for the alphabet to use and -g for the grouping. We also need to process the command line arguments passed in to the script to control password length, alphabet choice and grouping this can be done using the command-line macro, but since it is a macro, it interprets its arguments in a special way, which may be surprising if you expect a normal function call. ( define ( encode-bignum bignum alphabet group separator ) ( define base ( string-length alphabet )) ( let loop ( ) ( if ( > bignum 0 ) ( let-values (( ( quotient/remainder bignum base ))) ( let (( symbol ( string-ref alphabet r ))) NOTE: if `group` is 0, there is no grouping ( if ( and ( > group 0 ) ( > position 0 ) ( = ( remainder position group ) 0 )) ( loop ( add1 position ) ( cons symbol ( cons separator result )) q ) ( loop ( add1 position ) ( cons symbol result ) q )))) ( list->string ( reverse result ))))) ![]() The normal-alphabet will use upper and lower-case letters plus digits, the lower-case-alphabet will use lower case letters plus digits and a simplified-alphabet will use a combination of letters and numbers which cannot be mistaken for each other (for example, it does not contain the letter l or the digit 1): We will define four alphabets for encoding the passwords: the full-alphabet will use upper and lower-case letters, digits plus some symbols, this will produce the shortest passwords for a given bit length, but it might create passwords which are difficult to type. To make it more interesting, the utility will accept command line arguments to select password strength, the alphabets to use for encoding, and will allow grouping of letters to make passwords easier to use. ![]() We have all the building blocks we need to build a simple command line utility to generate passwords. Pwgen.rkt> ( encode-bignum number "abcdef" ) "cbdacfaebbfdefadbfdadfcfdcbfffecbcdfeafdfddbbddabc" It is more convenient to use the usual arithmetic operations even if the numbers involved have 512 or 1024 bits: Since Racket supports arbitrarily large integers, we can write a function which converts the random bytes into a single big integer. However, the function returns a vector of bytes, rather than a single integer. To generate a secure random number, we can use the Racket crypto-random-bytes function, this function uses the underlying OS facilities to generate cryptographically secure random numbers. Two things are needed to generate a secure password: a cryptographically secure random number and a way to convert this number in a string of letters, numbers and symbols which can be used as a password. ![]() You may already use a password manager and may not have a need for a new one, still, this blog post might show you a few useful techniques for building Racket applications. ![]() This blog post shows how to build a simple password generator. There are many places in todays world where you need to provide a password and, since it is not recommended to reuse them, you will need to come up with many such passwords, all of them preferably secure. Writing a Simple Password Generator in Racket
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |