#202668 - 2011-07-15 10:47 AM
Re: Encrypt/Decrypt String
[Re: Richard H.]
|
Richard H.
Administrator
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Assuming that you are after a password, this will do the trick:
Function Passgen($iLen,Optional $sSalt,$sRequires)
Dim $iSalt,$i,$t,$s
Dim $asTemplate[]
Dim $sAlphaUpper,$sAlphaLower,$sNumeric,$sSpecial,$iRand
$sAlphaUpper="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
$sAlphaLower="abcdefghijklmnopqrstuvwxyz"
$sNumeric="1234567890"
$sSpecial="!£$$%^&*()_+-=[]{};;@@#~,./<>?"
If CInt($iLen)<Len($sRequires) $iLen=Len($sRequires) EndIf
ReDim $asTemplate[$iLen-1]
; If no salt is specified then create on based on the date/time
If $sSalt="" $sSalt=@DATE+@TIME+@MSECS EndIf
; Convert salt string to numeric
$iSalt=54321
While $sSalt<>""
$iSalt=($iSalt*10+Asc($sSalt))
$sSalt=SubStr($sSalt,2)
Loop
; Seed RNG, discard first result
SRND($iSalt) $Passgen=Rnd()
; Create template
For $i = 1 To $iLen
If SubStr($sRequires,$i,1)=""
$asTemplate[$i-1]="?"
Else
$asTemplate[$i-1]= SubStr($sRequires,$i,1)
EndIf
Next
$Passgen=""
For $i = $iLen To 1 Step -1
$iRand=IIf($i=1,0,RND($i-1))
Select
Case $asTemplate[$iRand]=="A"
$s=$sAlphaUpper
Case $asTemplate[$iRand]=="a"
$s=$sAlphaLower
Case $asTemplate[$iRand]="X" or $asTemplate[$iRand]="x"
$s=$sAlphaLower+$sAlphaUpper
Case $asTemplate[$iRand]="9"
$s=$sNumeric
Case $asTemplate[$iRand]="#"
$s=$sSpecial
Case Default
$s=$sAlphaUpper+$sAlphaLower+$sNumeric+$sSpecial
EndSelect
$Passgen=$Passgen+SubStr($s,Rnd(Len($s)-1)+1,1)
; Discard used template character
$asTemplate[$iRand]=""
$asTemplate=Split(Join(Split(Trim(Join($asTemplate))," ")))
Next
EndFunction
Paramters are: $iLen = Length of the password $sSalt = String that is used to generate the password - if you leave it blank then the current time is used. $sRequires = Password strength where the characters may be
- A - upper case letter
- a - lower case letter
- X - Upper or lowercase letter
- 9 - numeric
- # - Special
For you example:
Passgen(Len("Valentim"),"Valentim","XXX999#") ?
This should get you the result: b~6r15wI
|
Top
|
|
|
|
#202680 - 2011-07-15 10:12 PM
Re: Encrypt/Decrypt String
[Re: Richard H.]
|
Valentim
Fresh Scripter
Registered: 2010-01-04
Posts: 46
Loc: Brazil, PE, Recife
|
Assuming that you are after a password, this will do the trick: Paramters are: $iLen = Length of the password $sSalt = String that is used to generate the password - if you leave it blank then the current time is used. $sRequires = Password strength where the characters may be - A - upper case letter
- a - lower case letter
- X - Upper or lowercase letter
- 9 - numeric
- # - Special
For you example: Passgen(Len("Valentim"),"Valentim","XXX999#") ? This should get you the result: b~6r15wI
is exactly that, but also I'll need to read the decryption password correctly
_________________________
|
Top
|
|
|
|
#202723 - 2011-07-21 07:06 AM
Re: Encrypt/Decrypt String
[Re: Allen]
|
NTDOC
Administrator
Registered: 2000-07-28
Posts: 11623
Loc: CA
|
I agree with Allen, RunNas is a great tool especially once you have it figured out. Its replaced the use of a few other older method that used to be common around here many years ago.
AS for an AWESOME Password Script this one by Richard is amazing. I really had high hopes of creating a KiXform out of it and worked with Shawn on it but it turned out to be a bit too complex to do what we'd wanted to do with the time we had so it never did get completed.
Flexible password generator
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 507 anonymous users online.
|
|
|