For schleife - Arrays

  • Hey,

    hab gradn problem.

    Ich versuche jeden key den ich generiert habe zu crypten und dann in nem array zu speichern sprich $key[0]
    der 2te generierte dann $key[2] unsoweiter...

    aber ich habs net so mit for schleifen, bzw damit kann man mich jagen ...
    kann mir einer zeigen wie ich das am Besten mache?

    also es solln unendlich arrays gemacht werden, so oft halt wie ich den button klicke um nen neuen key zu generieren.

    Spoiler anzeigen
    [autoit]

    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    #include <String.au3>
    #include <Array.au3>
    #include <String.au3>

    [/autoit] [autoit][/autoit] [autoit]

    FileDelete(@ScriptDir & "\sessionkeys.rg")

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Local $key[21]
    Local $rkey[21]
    Global $lol
    Global $xD
    Global $value1
    Global $value2
    Global $value3
    Global $value4

    [/autoit] [autoit][/autoit] [autoit]

    GUICreate("Crypt Key Generator", 350, 220)
    $create = GUICtrlCreateButton("Create Key", 30, 20, 120, 25)
    GUICtrlCreateLabel("Created Key:", 30, 130, 120, 25)
    GUICtrlSetState(-1, $GUI_DISABLE)
    GUICtrlCreateLabel("Password for Cryption:", 200, 40, 200, 25)
    GUICtrlSetState(-1, $GUI_DISABLE)
    $generated = GUICtrlCreateInput("", 30, 160, 150, 25)
    $pass = GUICtrlCreateInput("risZerG", 200, 60, 100, 25)
    $save = GUICtrlCreateButton("Save Key to File", 30, 60, 120, 25)
    GUICtrlCreateButton("Update Database", 30, 90, 120, 25)
    GUISetState(@SW_SHOW)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    While 1
    $msg = GUIGetMsg()
    Switch $msg
    Case $create
    create()
    Case $save
    save()
    EndSwitch
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func randome()
    $lol = Random(0, 9, 4)
    $xD = _StringBetween($lol, ".", "")
    $value1 = StringTrimRight($xD[0], 10)
    $value2 = StringTrimLeft($xD[0], 10)
    $random2 = Random(0, 9)
    $key = _StringBetween($random2, ".", "")
    $value3 = StringTrimRight($key[0], 10)
    $value4 = StringTrimLeft($key[0], 10)
    EndFunc ;==>randome

    [/autoit] [autoit][/autoit] [autoit]

    Func create()
    randome()
    GUICtrlSetData($generated, $value1 & "-" & $value2 & "-" & $value3 & "-" & $value4)
    EndFunc ;==>create

    [/autoit] [autoit][/autoit] [autoit]

    Func save()
    $i = 0
    For $i = 0 To UBound($key) + 1
    $key = _StringEncrypt(1, $value1 & "-" & $value2 & "-" & $value3 & "-" & $value4, GUICtrlRead($pass), 5)
    MsgBox(0, "", $key)
    Next
    EndFunc ;==>save

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit]

    Gruß

    Einmal editiert, zuletzt von Kev (16. Juni 2010 um 16:38) aus folgendem Grund: Tidy

  • Ich würds so ändern.
    habs nur bissl aufgeräumt. muss jetzt weg. Die sonne wartet.

    Spoiler anzeigen
    [autoit]

    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    #include <String.au3>
    #include <Array.au3>
    #include <String.au3>

    [/autoit] [autoit][/autoit] [autoit]

    FileDelete(@ScriptDir & "\sessionkeys.rg")
    Global $aKeys[1]

    [/autoit] [autoit][/autoit] [autoit]

    GUICreate("Crypt Key Generator", 350, 220)
    $cBtnCreate = GUICtrlCreateButton("Create Key", 30, 20, 120, 25)
    GUICtrlCreateLabel("Created Key:", 30, 130, 120, 25)
    GUICtrlSetState(-1, $GUI_DISABLE)
    GUICtrlCreateLabel("Password for Cryption:", 200, 40, 200, 25)
    GUICtrlSetState(-1, $GUI_DISABLE)
    $cKey = GUICtrlCreateInput("", 30, 160, 150, 25)
    $cPass = GUICtrlCreateInput("risZerG", 200, 60, 100, 25)
    $cBtnSave = GUICtrlCreateButton("Save Key to File", 30, 60, 120, 25)
    GUICtrlCreateButton("Update Database", 30, 90, 120, 25)
    GUISetState(@SW_SHOW)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    While 1
    $msg = GUIGetMsg()
    Switch $msg
    Case -3
    Exit
    Case $cBtnCreate
    create()
    Case $cBtnSave
    save()
    EndSwitch
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func _GenerateKey()
    Local $aVal[4], $aRand
    $aRand = _StringBetween(Random(0, 9), ".", "")
    $aVal[0] = StringTrimRight($aRand[0], 10)
    $aVal[1] = StringTrimLeft($aRand[0], 10)
    $aRand = _StringBetween(Random(0, 9), ".", "")
    $aVal[2] = StringTrimRight($aRand[0], 10)
    $aVal[3] = StringTrimLeft($aRand[0], 10)
    Return $aVal[0] & "-" & $aVal[1] & "-" & $aVal[2] & "-" & $aVal[3]
    EndFunc ;==>randome

    [/autoit] [autoit][/autoit] [autoit]

    Func create()
    Local $sKey = _GenerateKey()
    GUICtrlSetData($cKey, $sKey)
    _ArrayAdd($aKeys,$sKey)
    EndFunc ;==>create

    [/autoit] [autoit][/autoit] [autoit]

    Func save()
    _ArrayDisplay($aKeys)
    For $i = 1 To UBound($aKeys) - 1
    $key = _StringEncrypt(1, $aKeys[$i], GUICtrlRead($cPass), 5)
    MsgBox(0, "Key "&$i, $key)
    Next
    EndFunc ;==>save

    [/autoit]
  • Spoiler anzeigen
    [autoit]

    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    #include <String.au3>
    #include <Array.au3>
    #include <String.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Global $aKeys[1]

    [/autoit] [autoit][/autoit] [autoit]

    GUICreate("Crypt Key Generator", 350, 420)
    $cBtnCreate = GUICtrlCreateButton("Create Key", 30, 20, 120, 25)
    GUICtrlCreateLabel("Created Key:", 30, 130, 120, 25)
    GUICtrlSetState(-1, $GUI_DISABLE)
    GUICtrlCreateLabel("Password for Cryption:", 200, 40, 200, 25)
    GUICtrlSetState(-1, $GUI_DISABLE)
    $cKey = GUICtrlCreateInput("", 30, 160, 150, 25)
    $cPass = GUICtrlCreateInput("risZerG", 200, 60, 100, 25)
    $cBtnSave = GUICtrlCreateButton("Save Key to File", 30, 60, 120, 25)
    $list = GUICtrlCreateList("",30,200,300,200)
    GUICtrlCreateButton("Update Database", 30, 90, 120, 25)
    GUISetState(@SW_SHOW)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    While 1
    $msg = GUIGetMsg()
    Switch $msg
    Case -3
    Exit
    Case $cBtnCreate
    create()
    Case $cBtnSave
    save()
    EndSwitch
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func _GenerateKey()
    Local $aVal[4], $aRand
    $aRand = _StringBetween(Random(0, 9), ".", "")
    $aVal[0] = StringTrimRight($aRand[0], 10)
    $aVal[1] = StringTrimLeft($aRand[0], 10)
    $aRand = _StringBetween(Random(0, 9), ".", "")
    $aVal[2] = StringTrimRight($aRand[0], 10)
    $aVal[3] = StringTrimLeft($aRand[0], 10)
    Return $aVal[0] & "-" & $aVal[1] & "-" & $aVal[2] & "-" & $aVal[3]
    EndFunc ;==>randome

    [/autoit] [autoit][/autoit] [autoit]

    Func create()
    Local $sKey = _GenerateKey()
    GUICtrlSetData($cKey, $sKey)
    _ArrayAdd($aKeys,$sKey)
    EndFunc ;==>create

    [/autoit] [autoit][/autoit] [autoit]

    Func save()
    For $i = 1 To UBound($aKeys) - 1
    $key = _StringEncrypt(1, $aKeys[$i], GUICtrlRead($cPass), 5)
    Filewrite(@ScriptDir & "\sessionkeys.rg",$key & @crlf)
    $arkey = _StringEncrypt(0,Fileread(@scriptdir & "\sessionkeys.rg",1),GUICtrlRead($cPass),5)
    msgbox(0,"",$arkey)
    Next
    EndFunc ;==>save

    [/autoit]

    hab grad noch das problem das die keys zwar gecryptet gespeichert werden, aber iwie krieg ich die dann nicht wieder entcryptet und ausgelesen.
    ich will einen key pro zeile und dann ne msgbox zb, die automatisch zeile 1 entcryptet un anzeigt dann zeile 2 usw.