View Single Post
  #8   (View Single Post)  
Old 28th August 2014
Mike-Sanders Mike-Sanders is offline
Fdisk Soldier
 
Join Date: Dec 2012
Posts: 52
Default

Some really great ideas, I must study the replies (thanks for sharing)!

Here's how I tackled the problem (but see note at end):

Code:
# phonetic.awk - Michael S. Sanders 2010
#
# This awk program file attempts produce phonetic passwords
# (ie - passwords that are easy to remember) using vowels/consonants.
# Additionally, the 1st letter of the password is capitalized and
# a single digit appended to the result. These two measures will
# satisfy the majority of sites that require alpha/numeric/mixed
# case passwords.
#
# Program usage requires two steps:
#
# - specify a number between 3 and 9 for the variable 'password_len'
#
# - invoke awk with the name of this file: 'awk -f phonetic.awk'
#
# sample output of five iterations: Yumo6, Gora5, Limo3, Wojo3, Kusa1
#

BEGIN {

  srand(seed+0)

  password_len = 5

  if (password_len < 3 || password_len > 9) {
    print "\nEnter a number 3 to 9...\n"
    exit
  }

  print password(password_len)

}

# ---------------------------------------------------------------------------

function password(num,    vwl, cns, tmp, bln, j) {

  vwl = "aeiou"             # vowels
  cns = "bdfghjklmnprstvwy" # consonants ('nice' only no C, X)

  tmp = toupper(substr(cns, rnum(1, 17), 1))

  for (j = 2; j <= num-1; j++) {
    if (! bln) {
      tmp = tmp substr(vwl, rnum(1,  5), 1); bln = 1
    } else {
      tmp = tmp substr(cns, rnum(1, 17), 1); bln = 0
    }
  }

  return tmp rnum(0, 9)
}

# ---------------------------------------------------------------------------

function rnum(low, hi,    x, y, z) {

  x = rand()
  y = (hi - low) + 1
  z = int((x * y) + low)

  return z
}

# eof
How does one generate random numbers in BSD using only awk without resorting to 3rd party tools? Multiple runs of this script under FreeBSD always produce the same result - randomness yes, but only once. I'm not sure how to solve this problem...
__________________
www.tacoshack.xyz
Reply With Quote