Valentim
(Fresh Scripter)
2011-07-14 09:12 PM
Encrypt/Decrypt String

it is possible to generate an encryption result using at least three letters, three numbers and a special character

I used Codec and dCodec of Glenn Barnas, but function not returns the encryption with the limitation of using three letters, three number and a special character

Example:
String: Valentim
Crypt: Ji$63e!4gk#9


Richard H.Administrator
(KiX Supporter)
2011-07-15 09:12 AM
Re: Encrypt/Decrypt String

Your question doesn't make sense the way that you have phrased it.

Do you mean that you want to generate a password for a string which conforms to the 3 letter, 3 numeric and special character requirement?

If this is not what you want then explain what you are going to use the encrypted string for.


Richard H.Administrator
(KiX Supporter)
2011-07-15 10:47 AM
Re: Encrypt/Decrypt String

Assuming that you are after a password, this will do the trick:
 Code:
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:
 Code:
Passgen(Len("Valentim"),"Valentim","XXX999#") ?


This should get you the result: b~6r15wI


Valentim
(Fresh Scripter)
2011-07-15 10:10 PM
Re: Encrypt/Decrypt String

 Originally Posted By: Richard H.
Your question doesn't make sense the way that you have phrased it.

Do you mean that you want to generate a password for a string which conforms to the 3 letter, 3 numeric and special character requirement?

If this is not what you want then explain what you are going to use the encrypted string for.


is a bit complicated to explain ...

I am using a logon script where I need to run some commands with administrator privilege using "runas" but I can not leave password set in arquivo.kix I must leave Encrypted password in a file and use "sanur" to read password within this file...

that's basically it...


Valentim
(Fresh Scripter)
2011-07-15 10:12 PM
Re: Encrypt/Decrypt String

 Originally Posted By: Richard H.
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:
 Code:
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


AllenAdministrator
(KiX Supporter)
2011-07-15 11:15 PM
Re: Encrypt/Decrypt String

You could try runnas, doubles n's are on purpose. It basically does everything and more than sanur. You can create a token file that hide the password.

http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=154040#Post154040


Glenn BarnasAdministrator
(KiX Supporter)
2011-07-15 11:45 PM
Re: Encrypt/Decrypt String

Look in the script vault.. there's a script that generates 32-byte/char strings for hashes. With minimal work you could generate something that met your requirements for passwords.

Glenn


NTDOCAdministrator
(KiX Master)
2011-07-21 07:06 AM
Re: Encrypt/Decrypt String

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