Jump to content

How can i generate a uneque 12 char coded string.


Recommended Posts

I'd like to generate a 12 character encrypted string that would always be 12 char and would always be uneque based on the password and keyword given.

The problem with _StringEncrypt is that the lenght is based on the keyword so longer keywords would generate massive codes.

Link to comment
Share on other sites

It's up to you to implement a propitary encryption method...You can really do anythign you want!

For instance-

MsgBox(0,"Encrypted string",CryptString("Hello World"))

Func CryptString($string)
    $Return=""
    for $a=1 to StringLen($string)
        $Return&=Chr(Asc(StringMid($string,$a,1))+1)
    Next
    Return $Return
EndFunc

That's just basic encryption. you can mess around with it however you wish or use an existing method that suits your needs...but don't expect someone to write you a custom encryption routine from scratch :D

(although these forums are a freindly place so you might get lucky)

Link to comment
Share on other sites

I'd like to generate a 12 character encrypted string that would always be 12 char and would always be uneque based on the password and keyword given.

The problem with _StringEncrypt is that the lenght is based on the keyword so longer keywords would generate massive codes.

If your not going to decrypt it, why not just cut the encrypted string off after 12 characters?

Cheers

Kurt

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

also it appears as though the result of _StringEncrypt is that each passcode char is encrypted into 4 chars. so if i cut it off at 12 char the string abcd would return the same as abcde or abcq

basically i'm trying to make an app version of this web site: http://www.hashapass.com/

here's the code i wrote:

#include <GUIConstants.au3>
#include <string.au3>
GUICreate ( 'Passgen' , 280 , 135 )
GUICtrlCreateLabel ( 'Keyword (Reminds you of what the password is used for)' , 3 , 3 )
$keyword=GUICtrlCreateInput ( '' , 3 , 20 , 275 )
GUICtrlCreateLabel ( 'Passcode (Keep secret used to encode)' , 3 , 43 )
$passcode=GUICtrlCreateInput ( '' , 3 , 60 , 275 , -1 , $ES_AUTOHSCROLL + $ES_LEFT + $ES_PASSWORD )
$button=GUICtrlCreateButton ( 'Create Password' , 3 , 83 , 275 )
$output=GUICtrlCreateInput ( '' , 3 , 110, 275 , 20 , $ES_READONLY )
GUISetState()
HotKeySet ( '{ENTER}' , '_Encrypt' )
While WinActive ( 'Passgen' )
    $msg = GUIGetMsg()
    Select
        Case $msg = $button
            _Encrypt()
        Case $msg = $GUI_EVENT_CLOSE
            Exit
    EndSelect
WEnd
Func _Encrypt ()
    $encrypted = _StringEncrypt ( 1 , GUICtrlRead ( $keyword ) , GUICtrlRead ( $passcode ) )
    GUICtrlSetData ( $output , $encrypted )
    ClipPut ( $encrypted )
EndFunc
Edited by Swimming_Bird
Link to comment
Share on other sites

  • Moderators

While 1
    If MsgBox(4, 'Testing Password', 'Your Password is: ' & _GeneratePassword() & @CRLF & 'Would you like to generate another?') = 7 Then Exit
WEnd

Func _GeneratePassword($s_SpecialCharacters = "#,$,?", $s_Dilemeter = ',', $i_PasswordLen = 12, $n_Lower_az = 3, $n_Upper_AZ = 3, $n_Numb09 = 3, $n_SpecialChar = 3)
    If $n_Lower_az + $n_Upper_AZ + $n_Numb09 + $n_SpecialChar <> $i_PasswordLen Then Return SetError(1, 0, 0)
    Local $s_Character = StringSplit($s_SpecialCharacters, $s_Dilemeter)
    Local $i_StringLenSC = StringLen(StringReplace($s_SpecialCharacters, $s_Dilemeter, ''))
    Local $i_Random[3], $s_Password = '', $i_Count[5]
    Do
        $i_Random[1] = Random(1, 4, 1)
        If $i_Random[1] = 1 And $i_Count[1] < $n_Lower_az Then
            $i_Count[1] += 1
            $i_Random[2] = Random(1, 26, 1)
            $s_Password &= Chr($i_Random[2] + 96)
        ElseIf $i_Random[1] = 2  And $i_Count[2] < $n_Upper_AZ Then
            $i_Count[2] += 1
            $i_Random[2] = Random(1, 26, 1)
            $s_Password &= Chr($i_Random[2] + 64)
        ElseIf $i_Random[1] = 3  And $i_Count[3] < $n_Numb09 Then
            $i_Count[3] += 1
            $i_Random[2] = Random(0, 9, 1)
            $s_Password &= $i_Random[2]
        ElseIf $i_Random[1] = 4  And $i_Count[4] < $n_SpecialChar Then
            $i_Count[4] += 1
            $i_Random[2] = Random(1, $i_StringLenSC, 1)
            $s_Password &= $s_Character[$i_Random[2]]
        EndIf
    Until StringLen($s_Password) = $i_PasswordLen
    Return $s_Password
EndFunc

Edit:

Code Tags

Edit2:

Been a while since I used that, cleaned it up just a little.

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Moderators

Here's another option looking at your GUI, you'll have to think of something good for the keyword thing...

#include <GUIConstants.au3>
#include <string.au3>
GUICreate ( 'Passgen' , 280 , 135 )
GUICtrlCreateLabel ( 'Keyword (Reminds you of what the password is used for)' , 3 , 3 )
$keyword=GUICtrlCreateInput ( '' , 3 , 20 , 275 )
GUICtrlCreateLabel ('Passcode (Keep secret used to encode)' , 3 , 43 )
$passcode=GUICtrlCreateInput ( '' , 3 , 60 , 275 , -1 , $ES_AUTOHSCROLL + $ES_LEFT + $ES_PASSWORD )
GUICtrlSetLimit($passcode, 6, 6);;;;;;;;;;;;;;; Note the limit set ;;;;;;;;;;;;;;;;;;;;;;
$button=GUICtrlCreateButton ( 'Create Password' , 3 , 83 , 275 )
$output=GUICtrlCreateInput ( '' , 3 , 110, 275 , 20 , $ES_READONLY )
GUISetState()
HotKeySet ( '{ENTER}' , '_Encrypt' )
While WinActive ( 'Passgen' )
    $msg = GUIGetMsg()
    Select
        Case $msg = $button
            _Encrypt()
            MsgBox(64, 'Info', 'Just to show it can be converted back' & @CR & _ConvertMask(GUICtrlRead($output)))
        Case $msg = $GUI_EVENT_CLOSE
            Exit
    EndSelect
WEnd
Func _Encrypt ()
    $Mask = _ConvertString(GUICtrlRead($passcode))
    GUICtrlSetData ($output , $Mask)
    ClipPut($Mask)
EndFunc

Func _ConvertString($sText, $iMask = 20)
    Local $vOutPut
    For $iCount = 1 To StringLen($sText)
        $vOutPut &= Chr(Asc(StringMid($sText, $iCount, 1))+$iMask)
    Next
    Return _StringToHex($vOutPut)
EndFunc

Func _ConvertMask($vText, $iMask = 20)
    $vText = _HexToString($vText)
    Local $vOutPut
    For $iCount = 1 To StringLen($vText)
        $vOutPut &= Chr(Asc(StringMid($vText, $iCount, 1))-$iMask)
    Next
    Return $vOutPut
EndFunc
Edit:

Didn't paste the whole code.

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

bhat about for things that result in less then 12 chars? a fixed list of ammendable chars doesnt seem like htat good an idea.

Well, then fill up your unencrypted data with some defined text until the encrypted data will allways generate at least 12 characters. That's called padding.

Cheers

Kurt

Edited by /dev/null

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...