[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Problems with "tr -s"

From: Davis, Ricardo C.
Subject: RE: Problems with "tr -s"
Date: Wed, 13 Mar 2002 15:18:30 -0500


Thanks for the response.  It appears I misunderstood the operation of "tr -s".  I was trying to remove any repeated character in a string; I thought "tr -s" would do so.  This is incorrect; "tr -s" replaces repeated characters with one character.

Although the reduction in randomness by my algorithm is relatively miniscule, your solution would be preferred if multiple instances of a character are allowed.


-----Original Message-----
From: Bob Proulx [mailto:address@hidden]
Sent: Saturday, February 23, 2002 12:40 AM
To: Davis, Ricardo C.
Cc: 'address@hidden'
Subject: Re: Problems with "tr -s"


> I'm using GNU textutils 2.0e on a RedHat Linux 6.2 box.  I've written a bash
> script to create a password based on the following criteria:  certain
> characters excluded, at least 10 characters long, and no repeated characters
> (see below).  I'm using mkpasswd to create the test password and "tr" to
> remove the unwanted and duplicate characters.

Ugh, can I call you a sadist?  Those passwords are really awful.  Fine
for a first time temporary.  But I hope you are not forcing users to
remember passwords like hRK37s8Bue, yAJq8V01hw, and mb7CPzh68D!

> When I run this script, it appears that none of the duplicate characters are
> removed.  I added the last line to double-check by attempting to remove the
> duplicates -- without success.  Is this a known bug?  Thanks for your help
> with this issue.

I don't see the problem.  I have a version 2.0e handy and it worked
fine for me.

>    newpw=`mkpasswd -2 -l 10 -d 3 -C 3 | tr -ds 'l1O08B' '[:alnum:]'`

Let's break this down into parts.  Let's say that mkpasswd generates
'R9dNgl1Y2u' (which is did for me) and this is run through tr.

  echo R9dNgl1Y2u | tr -ds 'l1O08B' '[:alnum:]'

The 'l' and the '1' were in the delete list and were deleted.  Another
few runs and I was able to get this next.

  echo cu227ORPwj | tr -ds 'l1O08B' '[:alnum:]'

Since the '2' is a repeated character and an alnum it was squeezed.
The 'O' being in the delete list was deleted.

Let's try another test.

  echo 1222234445aaabcd5647 | tr -ds 'l1O08B' '[:alnum:]'

Looks like it is working to me.  What are you seeing?

> pwlen=0
> until [ $pwlen -ge 11 ]
> do
>    newpw=`mkpasswd -2 -l 10 -d 3 -C 3 | tr -ds 'l1O08B' '[:alnum:]'`
>    pwlen=`echo $newpw | wc -c`
>    echo -n "."
> #   echo -n $pwlen
> #   break
> done
> echo; echo $newpw
> echo "$newpw" | tr -s '[:alnum:]'

Looking at your script it looks like you are taking the long road.
You are in a loop cutting out characters and retrying until you get
one that does not have the characters to cut out.  But they are just
random characters to begin with.  Perhaps you could make a longer
string of random characters and just cut it down to the size you
wanted in one step and remove the looping?  Something like this?

  mkpasswd -2 -l 20 -d 6 -C 6 | tr -ds 'l1O08B' '[:alnum:]' | cut -c-10

Also, by squeezing out random characters which randomly happen to be
repeated you are removing randomness.  By analogy if you flip a coin
you will get either heads or tails, leaving out the possibilities of
landing on edge or of losing the coin during the toss.  If you squeeze
repeats out of a series of coin tosses you will end up with a
predictable pattern that would not be there if you kept the randomness
in place.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]