Chiffrierungstool

  • Hallo Leutz,

    Ich wollte mich an eine Dechiffrierungsmaschine begeben.
    Jeder kennt ja von euch Enigma, ne? :)

    Okay.
    Ich weiß zwar, wie ich das machen werde.

    Ein Code besteht bisher noch nicht, nur meine Frage ist nun:

    Wie kann ich von einem Text, den ich in ein Eingabefeld eingebe, jeden einzelnen Buchstaben als neuen Arraywert speichern?


    Ich habe absolut keine Ahnung, wie ich das machen soll :S


    Ich bedanke mich dann schonmal im vorraus,

    Schrubber :)

  • Hi,

    [autoit]

    #include <array.au3>
    $string = InputBox ("Test", "Bitte Text eingeben....")
    Dim $arstring [StringLen ($string)]
    For $i = 0 To UBound ($arstring) - 1
    $arstring [$i] = StringMid ($string, $i + 1, 1)
    Next
    _Arraydisplay ($arstring)

    [/autoit]

    ;-))
    Stefan

  • Okay. Habe nun mal das Fenster gemacht und angeschaut, wie ich das nun mit dem String mache. Dabei bin ich nun soweit:

    Spoiler anzeigen
    [autoit]

    #include <ButtonConstants.au3>
    #include <EditConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>
    #Region ### START Koda GUI section ### Form=
    $Enigma = GUICreate("Enigma", 442, 413, 344, 193)
    $head = GUICtrlCreateLabel("Enigma", 161, 16, 119, 41)
    GUICtrlSetFont(-1, 24, 800, 0, "MS Sans Serif")
    GUICtrlSetColor(-1, 0xFF0000)
    $title_eingabe = GUICtrlCreateLabel("Text:", 32, 70)
    $eingabe = GUICtrlCreateInput("", 32, 88, 385, 89)
    GUICtrlSetData(-1, "")
    $title_ausgabe = GUICtrlCreateLabel("Hex:", 32, 206)
    $ausgabe = GUICtrlCreateEdit("", 32, 224, 385, 89)
    GUICtrlSetData(-1, "")
    $code = GUICtrlCreateButton("codieren", 36, 336, 121, 25, $WS_GROUP)
    $copyright = GUICtrlCreateLabel("Scripted by UWC | Schrubber @ 2009", 8, 392, 184, 17)
    $zwischenablage = GUICtrlCreateButton("Zwischenablage", 165, 336, 121, 25, $WS_GROUP)
    $quit = GUICtrlCreateButton("Quit", 295, 336, 121, 25, $WS_GROUP)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit

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

    Case $code
    Dim $arstring [StringLen ($eingabe)]
    For $i = 0 To UBound ($arstring) - 1
    $arstring [$i] = StringMid ($eingabe, $i + 1, 1)
    Next
    MSGBOX(1, "test", $arstring [0])
    Case $quit
    Exit

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

    EndSwitch
    WEnd

    [/autoit]

    Aber egal, welche Teste ich dort eingebe, gibt er mir unabhängig 5 aus, wenn ich auf das draufdrück.

    • Offizieller Beitrag

    Du musst das Eingabefeld mit GUICtrlRead auslesen:

    Spoiler anzeigen
    [autoit]


    #include <array.au3>
    #include <ButtonConstants.au3>
    #include <EditConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>
    #Region ### START Koda GUI section ### Form=
    $Enigma = GUICreate("Enigma", 442, 413, 344, 193)
    $head = GUICtrlCreateLabel("Enigma", 161, 16, 119, 41)
    GUICtrlSetFont(-1, 24, 800, 0, "MS Sans Serif")
    GUICtrlSetColor(-1, 0xFF0000)
    $title_eingabe = GUICtrlCreateLabel("Text:", 32, 70)
    $gui_eingabe = GUICtrlCreateInput("", 32, 88, 385, 89)
    GUICtrlSetData(-1, "")
    $title_ausgabe = GUICtrlCreateLabel("Hex:", 32, 206)
    $ausgabe = GUICtrlCreateEdit("", 32, 224, 385, 89)
    GUICtrlSetData(-1, "")
    $code = GUICtrlCreateButton("codieren", 36, 336, 121, 25, $WS_GROUP)
    $copyright = GUICtrlCreateLabel("Scripted by UWC | Schrubber @ 2009", 8, 392, 184, 17)
    $zwischenablage = GUICtrlCreateButton("Zwischenablage", 165, 336, 121, 25, $WS_GROUP)
    $quit = GUICtrlCreateButton("Quit", 295, 336, 121, 25, $WS_GROUP)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit

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

    Case $code
    $eingabe = GUICtrlRead($gui_eingabe) ; Ein Gui-Element wird mit GUICtrlRead ausgelesen
    Dim $arstring[StringLen($eingabe)]
    For $i = 0 To UBound($arstring) - 1
    $arstring[$i] = StringMid($eingabe, $i + 1, 1)
    Next
    _ArrayDisplay($arstring)
    Case $quit
    Exit

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

    EndSwitch
    WEnd

    [/autoit]
    • Offizieller Beitrag

    Aber wie gesagt, einfach StringSplit mit Leerstring. ;)

    Spoiler anzeigen
    [autoit]

    #include <ButtonConstants.au3>
    #include <EditConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>
    #Region ### START Koda GUI section ### Form=
    $Enigma = GUICreate("Enigma", 442, 413, 344, 193)
    $head = GUICtrlCreateLabel("Enigma", 161, 16, 119, 41)
    GUICtrlSetFont(-1, 24, 800, 0, "MS Sans Serif")
    GUICtrlSetColor(-1, 0xFF0000)
    $title_eingabe = GUICtrlCreateLabel("Text:", 32, 70)
    $eingabe = GUICtrlCreateInput("", 32, 88, 385, 89)
    GUICtrlSetData(-1, "")
    $title_ausgabe = GUICtrlCreateLabel("Hex:", 32, 206)
    $ausgabe = GUICtrlCreateEdit("", 32, 224, 385, 89)
    GUICtrlSetData(-1, "")
    $code = GUICtrlCreateButton("codieren", 36, 336, 121, 25, $WS_GROUP)
    $copyright = GUICtrlCreateLabel("Scripted by UWC | Schrubber @ 2009", 8, 392, 184, 17)
    $zwischenablage = GUICtrlCreateButton("Zwischenablage", 165, 336, 121, 25, $WS_GROUP)
    $quit = GUICtrlCreateButton("Quit", 295, 336, 121, 25, $WS_GROUP)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $code
    GUICtrlSetData($ausgabe, '')
    Dim $arstring = StringSplit(GUICtrlRead($eingabe), ''), $str = ''
    For $i = 1 To UBound($arstring) -1
    $str &= StringUpper(Hex(Asc($arstring[$i]), 2)) & ' '
    Next
    GUICtrlSetData($ausgabe, $str)
    Case $quit
    Exit
    EndSwitch
    WEnd

    [/autoit]
  • Hi,

    Danke das Du den komplizierten Weg gehen willst.

    Habe aber Deinen Code mit BugFixens Vorschlag abgeändert:

    Spoiler anzeigen
    [autoit]

    #include <ButtonConstants.au3>
    #include <EditConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>
    #include <array.au3> ; wird nur für das _Arraydisplay benötigt, zum Verständnis

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

    #Region ### START Koda GUI section ### Form=
    $Enigma = GUICreate("Enigma", 442, 413, 344, 193)
    $head = GUICtrlCreateLabel("Enigma", 161, 16, 119, 41)
    GUICtrlSetFont(-1, 24, 800, 0, "MS Sans Serif")
    GUICtrlSetColor(-1, 0xFF0000)
    $title_eingabe = GUICtrlCreateLabel("Text:", 32, 70)
    $eingabe = GUICtrlCreateInput("", 32, 88, 385, 89)
    GUICtrlSetData(-1, "")
    $title_ausgabe = GUICtrlCreateLabel("Hex:", 32, 206)
    $ausgabe = GUICtrlCreateEdit("", 32, 224, 385, 89)
    GUICtrlSetData(-1, "")
    $code = GUICtrlCreateButton("codieren", 36, 336, 121, 25, $WS_GROUP)
    $copyright = GUICtrlCreateLabel("Scripted by UWC | Schrubber @ 2009", 8, 392, 184, 17)
    $zwischenablage = GUICtrlCreateButton("Zwischenablage", 165, 336, 121, 25, $WS_GROUP)
    $quit = GUICtrlCreateButton("Quit", 295, 336, 121, 25, $WS_GROUP)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit

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

    Case $code
    If GuiCTRLRead ($eingabe) = "" Then
    MsgBox (0, "Eingabe", "Bitte Text eingeben!")
    Else
    $text = StringSplit (GUICtrlRead ($eingabe), "", 2)
    _Arraydisplay ($text)
    EndIf
    Case $quit
    Exit

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

    EndSwitch
    WEnd

    [/autoit]

    Wenn Du den Komplizierten Weg trotzdem gehen willst, mach
    1) #include <array.au3> am Anfang des Skriptes
    2) Ersetze MsgBox( 1, "test", $arstring [0]) durch ein _Arraydisplay ($arstring)

    Mit $arstring [0] erhälst Du entweder die Anzahl der Elemente in dem Array oder das Element selbst.
    Hängt davon ab, wie das Array aufgebaut ist. Lies nochmal in der Hilfe nach .

    ;-))
    Stefan

    P.S: Viel zu spät

  • OKay, danke für die Hilfe schonmal.
    Nun ist das Tool fertig, was mir den Code als Hex Chiffriert.

    Um das aber nun umzukehren, hab ich eig so gedacht:

    [autoit]


    Case $decode
    GUICtrlSetData($ausgabe, '')
    Dim $chstring = StringSplit(GUICtrlRead($eingabe), ''), $str2 = ''
    For $ii = 2 To UBound($chstring) -1
    $str2 &= StringUpper(ASC(HEX($chstring[$ii]), 2)) & ' '
    Next
    GUICtrlSetData($ausgabe, $str2)

    [/autoit]

    Aber das funktioniert bei mir nicht, da der mir ausgibt:

    Zitat

    ERROR: Asc() [built-in] called with wrong number of args.
    $str2 &= StringUpper(ASC(HEX :$chstring[$ii]), 2)

    Ich weiß nicht, was ich falsch gemacht hab :(
    Er soll mir ja den ASCI Code von dem Hexcode der Variable $chstring ausgeben. Oder sehe ich das falsch?

  • Aah stimmt :D

    [autoit]

    #include <ButtonConstants.au3>
    #include <EditConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>
    #include <String.au3>

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

    #Region ### START Koda GUI section ### Form=
    $Enigma = GUICreate("Enigma", 442, 413, 344, 193)
    $head = GUICtrlCreateLabel("Enigma", 161, 20, 119, 41)
    GUICtrlSetFont(-1, 24, 800, 0, "MS Sans Serif")
    GUICtrlSetColor(-1, 0xFF0000)
    $title_eingabe = GUICtrlCreateLabel("Eingabe:", 32, 70)
    $eingabe = GUICtrlCreateInput("", 32, 88, 385, 89)
    GUICtrlSetData(-1, "")
    $title_ausgabe = GUICtrlCreateLabel("Ausgabe:", 32, 206)
    $ausgabe = GUICtrlCreateEdit("", 32, 224, 385, 89)
    GUICtrlSetData(-1, "")
    $information1 = GUICtrlCreateLabel("Text to Hex -> codieren", 32, 318)
    $information2 = GUICtrlCreateLabel("Hex to Text -> decodieren", 32, 333)
    $code = GUICtrlCreateButton("codieren", 36, 356, 121, 25, $WS_GROUP)
    $copyright = GUICtrlCreateLabel("Scripted by UWC | Schrubber @ 2009", 8, 392, 184, 17)
    $decode = GUICtrlCreateButton("decodieren", 165, 356, 121, 25, $WS_GROUP)
    $quit = GUICtrlCreateButton("Quit", 295, 356, 121, 25, $WS_GROUP)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

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

    $byte = 1

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $code
    GUICtrlSetData($ausgabe, '')
    Dim $arstring = StringSplit(GUICtrlRead($eingabe), ''), $str = ''
    For $i = 1 To UBound($arstring) -1
    $str &= StringUpper(Hex(Asc($arstring[$i]), 2)) & ' '
    Next
    GUICtrlSetData($ausgabe, $str)

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

    Case $decode
    GUICtrlSetData($ausgabe, '')
    Dim $chstring = StringSplit(GUICtrlRead($eingabe), ''), $str2 = ''
    For $ii = 2 To UBound($chstring) -1
    $str2 &= StringUpper(ASC(HEX($chstring[$ii], 2))) & ' '
    Next
    GUICtrlSetData($ausgabe, $str2)

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

    Case $quit
    Exit
    EndSwitch
    WEnd

    [/autoit]

    Das codieren funktioniert perfekt, aber nicht das decodieren.

  • Spoiler anzeigen
    [autoit]

    #include <ButtonConstants.au3>
    #include <EditConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>
    #include <String.au3>

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

    #Region ### START Koda GUI section ### Form=
    $Enigma = GUICreate("Enigma", 442, 413, 344, 193)
    $head = GUICtrlCreateLabel("Enigma", 161, 20, 119, 41)
    GUICtrlSetFont(-1, 24, 800, 0, "MS Sans Serif")
    GUICtrlSetColor(-1, 0xFF0000)
    $title_eingabe = GUICtrlCreateLabel("Eingabe:", 32, 70)
    $eingabe = GUICtrlCreateInput("", 32, 88, 385, 89)
    GUICtrlSetData(-1, "")
    $title_ausgabe = GUICtrlCreateLabel("Ausgabe:", 32, 206)
    $ausgabe = GUICtrlCreateEdit("", 32, 224, 385, 89)
    GUICtrlSetData(-1, "")
    $information1 = GUICtrlCreateLabel("Text to Hex -> codieren", 32, 318)
    $information2 = GUICtrlCreateLabel("Hex to Text -> decodieren", 32, 333)
    $code = GUICtrlCreateButton("codieren", 36, 356, 121, 25, $WS_GROUP)
    $copyright = GUICtrlCreateLabel("Scripted by UWC | Schrubber @ 2009", 8, 392, 184, 17)
    $decode = GUICtrlCreateButton("decodieren", 165, 356, 121, 25, $WS_GROUP)
    $quit = GUICtrlCreateButton("Quit", 295, 356, 121, 25, $WS_GROUP)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

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

    $byte = 1

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $code
    GUICtrlSetData($ausgabe, '')
    Dim $arstring = StringSplit(GUICtrlRead($eingabe), ''), $str = ''
    For $i = 1 To UBound($arstring) -1
    $str &= StringUpper(Hex(Asc($arstring[$i]), 2)) & ' '
    Next
    GUICtrlSetData($ausgabe, $str)

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

    Case $decode
    GUICtrlSetData($ausgabe, '')
    Dim $chstring = StringSplit(GUICtrlRead($eingabe), ''), $str2 = ''
    For $ii = 1 To $chstring[0] Step 3
    $hex = $chstring[$ii] & $chstring[$ii+1]
    $str2 &= Chr(Dec($hex))
    Next
    GUICtrlSetData($ausgabe, $str2)

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

    Case $quit
    Exit
    EndSwitch
    WEnd

    [/autoit]