Page 1 of 1 1
Topic Options
#202666 - 2011-07-14 09:12 PM Encrypt/Decrypt String
Valentim Offline
Fresh Scripter

Registered: 2010-01-04
Posts: 46
Loc: Brazil, PE, Recife
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


Edited by Valentim (2011-07-14 09:20 PM)
_________________________

Top
#202667 - 2011-07-15 09:12 AM Re: Encrypt/Decrypt String [Re: Valentim]
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
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.

Top
#202668 - 2011-07-15 10:47 AM Re: Encrypt/Decrypt String [Re: Richard H.]
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
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

Top
#202678 - 2011-07-15 10:10 PM Re: Encrypt/Decrypt String [Re: Richard H.]
Valentim Offline
Fresh Scripter

Registered: 2010-01-04
Posts: 46
Loc: Brazil, PE, Recife
 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...
_________________________

Top
#202680 - 2011-07-15 10:12 PM Re: Encrypt/Decrypt String [Re: Richard H.]
Valentim Offline
Fresh Scripter

Registered: 2010-01-04
Posts: 46
Loc: Brazil, PE, Recife
 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
_________________________

Top
#202683 - 2011-07-15 11:15 PM Re: Encrypt/Decrypt String [Re: Valentim]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
Loc: USA
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

Top
#202686 - 2011-07-15 11:45 PM Re: Encrypt/Decrypt String [Re: Allen]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
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
_________________________
Actually I am a Rocket Scientist! \:D

Top
#202723 - 2011-07-21 07:06 AM Re: Encrypt/Decrypt String [Re: Allen]
NTDOC Administrator Offline
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
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 248 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.057 seconds in which 0.021 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org