Jump to content

pluto41

Active Members
  • Posts

    60
  • Joined

  • Last visited

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

pluto41's Achievements

Wayfarer

Wayfarer (2/7)

11

Reputation

  1. I did a attempt in 2016 to make a Enigma machine. I'm not coding much anymore since some years so i thought i'd better release what i did come up. Its working code. Encrypts and Decrypts. Optional word space can be turned of and on. Optional SHA256 encode the already Enigma encrypted code. There's still a small error somewhere but i don't have time or do want to fix that. Anyway perhaps someone can use this code and make it better or just play with it for fun. ;=============================================================================== ; Author: 48Pluto 23 januari 2016 ; Program Name: My_Enigma.exe ; National Geographic Code Breakers [https://www.youtube.com/watch?v=JOL6J13hHyU] ; The Complexity of CODES - History Documentary Films [https://www.youtube.com/watch?v=sMQqK6NmRyc] ;=============================================================================== #include <array.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <StaticConstants.au3> #include <EditConstants.au3> #include <Date.au3> #include <Crypt.au3> ; Options Opt ( 'MustDeclareVars', 1 ) Opt ( 'GUIOnEventMode', 1 ) ; Constants Const $WindowTitle = " Encryptie Machine - Versie 1.02 - (c) Pluut 7-02-2016" Const $SuperEncrypt = False Const $DEBUG = False ; Declare and Initialize GUI Variables Global $mainUiHeight = 420 Global $mainUiWidth = 800 Global $TOPMARGIN = 10 ; gets adjusted troughout the program Global $LEFTMARGIN = 10 ; left margin Global $RIGHTMARGIN = $mainUiWidth - (2 * $LEFTMARGIN) ; right margin Local $BUTTON_HEIGHT = 25 Local $BUTTON_WIDTH = 90 Local $TEXT_BOX_HEIGHT = 150 ; Salt Input Local $mod1 = mod ( _WeekNumberISO (), 3 ) Local $mod2 = mod ( $mod1, 3 ) + $mod1 * 2 ;Local $day = @MDAY ; code is valid for today only Local $day = _WeekNumberISO () ; code is valid for this week only Local $sSuperEncryptKey = "until" & $day ; code is valid for this week only Local $iAlgorithm = $CALG_AES_256 ; Global Settings Global $aRotorInit [9] = [ 0,0,$day,0,0,0,0,0,0 ] ; SLT Global $aRotor = $aRotorInit Global $aWiringRotor_0_1 [26] Global $aWiringRotor_1_2 [26] Global $aWiringRotor_2_3 [26] Global $aWiringRotor_3_4 [26] Global $aWiringRotor_4_5 [26] Global $aWiringRotor_5_6 [26] Global $aWiringRotor_6_7 [26] Global $aWiringRotor_7_8 [26] Global $aWiringRotor_8_9 [26] ; User Interface Local $hGUI = GUICreate ( $WindowTitle, $mainUiWidth, $mainUiHeight, -1, -1, $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS + $WS_CLIPCHILDREN ) GUISetBkColor ( 0xD8D8D8 ) GUISetIcon( @ScriptDir & "\au3script_v9.ico" ) ; Create Input Text Box Label Local $GUIStatusMessage = GUICtrlCreateLabel ( "", $LEFTMARGIN, $TOPMARGIN, $mainUiWidth - $LEFTMARGIN, 20 ) GUICtrlSetFont ( $GUIStatusMessage, 11, 590, 0, "Helvetica" ) GUICtrlSetData ( $GUIStatusMessage, StringLeft("Voer de tekst in:", 60 ) ) ; Create Output Text Box Label Local $GUIStatusMessage = GUICtrlCreateLabel ( "", $LEFTMARGIN, $TOPMARGIN + $TEXT_BOX_HEIGHT + 35, $mainUiWidth - $LEFTMARGIN, 20 ) GUICtrlSetFont ( $GUIStatusMessage, 11, 590, 0, "Helvetica" ) GUICtrlSetData ( $GUIStatusMessage, StringLeft("Resultaat:", 60 ) ) ; Create Text Boxes Local $TXT_INPUT = GUICtrlCreateInput ( "", $LEFTMARGIN, $TOPMARGIN + 25, $RIGHTMARGIN, $TEXT_BOX_HEIGHT, $ES_MULTILINE ) Local $TXT_OUTPUT = GUICtrlCreateInput ( "", $LEFTMARGIN, $TOPMARGIN + $TEXT_BOX_HEIGHT + 60, $RIGHTMARGIN, $TEXT_BOX_HEIGHT, $ES_MULTILINE ) ; Create Buttons Local $BTN_ENCRYPT = GUICtrlCreateButton ( "Encrypt", $LEFTMARGIN + $BUTTON_WIDTH * 4 + 100, $mainUiheight - 35, $BUTTON_WIDTH, $BUTTON_HEIGHT ) Local $BTN_DECRYPT = GUICtrlCreateButton ( "Decrypt", $LEFTMARGIN + $BUTTON_WIDTH * 5 + 120, $mainUiheight - 35, $BUTTON_WIDTH, $BUTTON_HEIGHT ) Local $BTN_CLOSEPROGRAM = GUICtrlCreateButton ( "Afsluiten", $RIGHTMARGIN - $BUTTON_WIDTH + $LEFTMARGIN, $mainUiheight - 35, $BUTTON_WIDTH, $BUTTON_HEIGHT ) ; Set the GUI Events GUICtrlSetOnEvent ( $BTN_CLOSEPROGRAM, "_GUI_closeOnEvent" ) GUICtrlSetOnEvent ( $BTN_ENCRYPT, "_GUI_Encrypt" ) GUICtrlSetOnEvent ( $BTN_DECRYPT, "_GUI_Decrypt" ) ; Show the GUI GUISetState ( @SW_SHOW ) ; Init Local $iCount = 0 InitialiseMachineSettings ( ) While 1 Sleep ( 200 ) Wend ;==> Main Loop() ; ================================== ; Func _GUI_Encrypt ( ) ; ================================== Func _GUI_Encrypt ( ) $aRotor = $aRotorInit ; Reset the Rotor Wheels Local $sSecret = GUICtrlRead ( $TXT_INPUT ) Local $sEncoded = Encode ( $sSecret, "encode" ) ; Encode $sEncoded = StringReplace ( $sEncoded, "|", "" ) If $DEBUG = True Then ConsoleWrite ( "Encoded: " & $sEncoded & @CRLF ) If $SuperEncrypt = True Then $sEncoded = _Crypt_EncryptData ( $sEncoded, $sSuperEncryptKey, $iAlgorithm ) $sEncoded = BinaryToString ( $sEncoded ) EndIf ControlSetText ( "", "", $TXT_OUTPUT, $sEncoded ) EndFunc ;==> _GUI_Encrypt ; ================================== ; Func _GUI_Decrypt ( ) ; ================================== Func _GUI_Decrypt ( ) $aRotor = $aRotorInit ; Reset the Rotor Wheels Local $sSecret = GUICtrlRead ( $TXT_INPUT ) If $SuperEncrypt = True Then $sSecret = _Crypt_DecryptData ( $sSecret, $sSuperEncryptKey, $iAlgorithm ) $sSecret = BinaryToString ( $sSecret ) EndIf Local $sDecoded = Encode ( $sSecret, "decode" ) ; Decode $sDecoded = StringReplace ( $sDecoded, "|", "" ) If $DEBUG = True Then ConsoleWrite ( "Decoded: " & $sDecoded & @CRLF ) ControlSetText ( "", "", $TXT_OUTPUT, $sDecoded ) EndFunc ;==> _GUI_Decrypt ; ================================== ; Func Encode ( code ) ; ================================== Func Encode ( $sCode, $action ) Local $iPosFound, $sEncodeChar If $action <> "encode" And $action <> "decode" Then MsgBox ( 6, "Error", "Function Encode called with wrong arguments" ) Return EndIf Local $aCode = StringSplit ( $sCode, "" ) _ArrayDelete ( $aCode, 0 ) For $n = 0 to UBound ( $aCode ) - 1 If $action = "encode" Then $sEncodeChar = CodeScramble ( $aCode [$n], "encode" ) ; 1 If $action = "decode" Then $sEncodeChar = CodeScramble ( $aCode [$n], "decode" ) ; 1 $aCode [$n] = $sEncodeChar Next Return ( _ArrayToString ( $aCode ) ) EndFunc ;==> Encode ; ================================== ; Func CodeScramble ( character, encode/decode ) ; ================================== Func CodeScramble ( $sChar, $action ) Local $aWireCombo ; Contains 0=index, 1=start value, 2=end value Local $retValue If $sChar = " " Then ; Verwijder de spaties uit de encryptie / decryptie [maakt lezen moeilijker maar reversed engineering ook] ;RotorRotate ( ) ; wil je wel spaties uncomment deze regel (stap 1) Return "" ; wil je wel spaties dan return " " (laatste stap) EndIf If $action = "encode" Then $retValue = PassRotor ( $sChar, "encode" ) Return $retValue ElseIf $action = "decode" Then $retValue = PassRotor ( $sChar, "decode" ) Return $retValue Else MsgBox ( 6, "Error", "Function CodeScramble called with wrong arguments" ) EndIf EndFunc ; ================================== ; Func PassRotor ( ) ; ================================== Func PassRotor ( $sChar, $action ) Local $iSecretRotorNumber, $aWireCombo If $action <> "encode" And $action <> "decode" Then MsgBox ( 6, "Error", "Function CodeScramble called with wrong arguments" ) Return EndIf $iSecretRotorNumber = RotorRotate () ConsoleWrite ( $iSecretRotorNumber & " " ) Select Case $iSecretRotorNumber = 14 Or $iSecretRotorNumber = 3 if $action = "encode" Then For $i = 0 to UBound ( $aWiringRotor_0_1 ) - 1 $aWireCombo = StringSplit ( $aWiringRotor_0_1 [$i], "," ) If $aWireCombo [1] = $sChar Then Return $aWireCombo [2] Next Else For $i = 0 to UBound ( $aWiringRotor_0_1 ) - 1 $aWireCombo = StringSplit ( $aWiringRotor_0_1 [$i], "," ) If $aWireCombo [2] = $sChar Then Return $aWireCombo [1] Next EndIf Case $iSecretRotorNumber = 13 Or $iSecretRotorNumber = 4 if $action = "encode" Then For $i = 0 to UBound ( $aWiringRotor_1_2 ) - 1 $aWireCombo = StringSplit ( $aWiringRotor_1_2 [$i], "," ) If $aWireCombo [1] = $sChar Then Return $aWireCombo [2] Next Else For $i = 0 to UBound ( $aWiringRotor_1_2 ) - 1 $aWireCombo = StringSplit ( $aWiringRotor_1_2 [$i], "," ) If $aWireCombo [2] = $sChar Then Return $aWireCombo [1] Next EndIf Case $iSecretRotorNumber = 12 Or $iSecretRotorNumber = 2 if $action = "encode" Then For $i = 0 to UBound ( $aWiringRotor_2_3 ) - 1 $aWireCombo = StringSplit ( $aWiringRotor_2_3 [$i], "," ) If $aWireCombo [1] = $sChar Then Return $aWireCombo [2] Next Else For $i = 0 to UBound ( $aWiringRotor_2_3 ) - 1 $aWireCombo = StringSplit ( $aWiringRotor_2_3 [$i], "," ) If $aWireCombo [2] = $sChar Then Return $aWireCombo [1] Next EndIf Case $iSecretRotorNumber = 11 Or $iSecretRotorNumber = 6 if $action = "encode" Then For $i = 0 to UBound ( $aWiringRotor_3_4 ) - 1 $aWireCombo = StringSplit ( $aWiringRotor_3_4 [$i], "," ) If $aWireCombo [1] = $sChar Then Return $aWireCombo [2] Next Else For $i = 0 to UBound ( $aWiringRotor_3_4 ) - 1 $aWireCombo = StringSplit ( $aWiringRotor_3_4 [$i], "," ) If $aWireCombo [2] = $sChar Then Return $aWireCombo [1] Next EndIf Case $iSecretRotorNumber = 10 Or $iSecretRotorNumber = 7 if $action = "encode" Then For $i = 0 to UBound ( $aWiringRotor_4_5 ) - 1 $aWireCombo = StringSplit ( $aWiringRotor_4_5 [$i], "," ) If $aWireCombo [1] = $sChar Then Return $aWireCombo [2] Next Else For $i = 0 to UBound ( $aWiringRotor_4_5 ) - 1 $aWireCombo = StringSplit ( $aWiringRotor_4_5 [$i], "," ) If $aWireCombo [2] = $sChar Then Return $aWireCombo [1] Next EndIf Case $iSecretRotorNumber = 9 Or $iSecretRotorNumber = 16 if $action = "encode" Then For $i = 0 to UBound ( $aWiringRotor_5_6 ) - 1 $aWireCombo = StringSplit ( $aWiringRotor_5_6 [$i], "," ) If $aWireCombo [1] = $sChar Then Return $aWireCombo [2] Next Else For $i = 0 to UBound ( $aWiringRotor_5_6 ) - 1 $aWireCombo = StringSplit ( $aWiringRotor_5_6 [$i], "," ) If $aWireCombo [2] = $sChar Then Return $aWireCombo [1] Next EndIf Case $iSecretRotorNumber = 15 Or $iSecretRotorNumber = 5 if $action = "encode" Then For $i = 0 to UBound ( $aWiringRotor_8_9 ) - 1 $aWireCombo = StringSplit ( $aWiringRotor_8_9 [$i], "," ) If $aWireCombo [1] = $sChar Then Return $aWireCombo [2] Next Else For $i = 0 to UBound ( $aWiringRotor_8_9 ) - 1 $aWireCombo = StringSplit ( $aWiringRotor_8_9 [$i], "," ) If $aWireCombo [2] = $sChar Then Return $aWireCombo [1] Next EndIf Case $iSecretRotorNumber = 8 Or $iSecretRotorNumber = 1 if $action = "encode" Then For $i = 0 to UBound ( $aWiringRotor_6_7 ) - 1 $aWireCombo = StringSplit ( $aWiringRotor_6_7 [$i], "," ) If $aWireCombo [1] = $sChar Then Return $aWireCombo [2] Next Else For $i = 0 to UBound ( $aWiringRotor_6_7 ) - 1 $aWireCombo = StringSplit ( $aWiringRotor_6_7 [$i], "," ) If $aWireCombo [2] = $sChar Then Return $aWireCombo [1] Next EndIf Case Else if $action = "encode" Then For $i = 0 to UBound ( $aWiringRotor_7_8 ) - 1 $aWireCombo = StringSplit ( $aWiringRotor_7_8 [$i], "," ) If $aWireCombo [1] = $sChar Then Return $aWireCombo [2] Next Else For $i = 0 to UBound ( $aWiringRotor_7_8 ) - 1 $aWireCombo = StringSplit ( $aWiringRotor_7_8 [$i], "," ) If $aWireCombo [2] = $sChar Then Return $aWireCombo [1] Next EndIf EndSelect EndFunc ;==> PassRotor ; ================================== ; Func RotorRotate ( ) ; ================================== Func RotorRotate ( ) Local $RotorNum = 0 $aRotor [0] += 1 If $aRotor [0] > 2 Then $aRotor [1] += 1 $aRotor [0] -= 1 $RotorNum = 1 EndIf If $aRotor [1] > 2 Then $aRotor [2] += 1 $aRotor [1] -= 1 $RotorNum = 2 EndIf If $aRotor [2] > 2 Then $aRotor [3] += 1 $aRotor [2] -= 1 $RotorNum = 3 EndIf If $aRotor [3] > 2 Then $aRotor [4] += 1 $aRotor [3] -= 1 $RotorNum = 4 EndIf If $aRotor [4] > 2 Then $aRotor [5] += 1 $aRotor [4] -= 1 $RotorNum = 5 EndIf If $aRotor [5] > 2 Then $aRotor [6] += 1 $aRotor [5] -= 1 $RotorNum = 6 EndIf If $aRotor [6] > 2 Then $aRotor [6] -= 1 $aRotor [0] = 0 $aRotor [1] = 0 $aRotor [2] = 2 $aRotor [3] = 0 $aRotor [4] = 0 $aRotor [5] = 0 $aRotor [6] = 0 $aRotor = $aRotorInit ; Reset the Rotor Wheels EndIf ; _ArrayDisplay ( $aRotor ) $iCount = ( $aRotor [0] + $aRotor [1] + $aRotor [2] + $aRotor [3] + $aRotor [4] + $aRotor [5] + $aRotor [6] ) ; / ( $aRotor[$RotorNum] ) $iCount = int ( $iCount, 1 ) Return ( $iCount ) EndFunc ;==> RotorRotate ; ================================== ; Func InitialiseMachineSettings ( ) ; ================================== Func InitialiseMachineSettings ( ) $aWiringRotor_0_1 [0] = "A,Z" ; Rotor 0 to 1 $aWiringRotor_0_1 [1] = "B,K" $aWiringRotor_0_1 [2] = "C,M" $aWiringRotor_0_1 [3] = "D,F" $aWiringRotor_0_1 [4] = "E,L" $aWiringRotor_0_1 [5] = "F,G" $aWiringRotor_0_1 [6] = "G,D" $aWiringRotor_0_1 [7] = "H,Q" $aWiringRotor_0_1 [8] = "I,V" $aWiringRotor_0_1 [9] = "J,E" $aWiringRotor_0_1 [10] ="K,N" $aWiringRotor_0_1 [11] ="L,T" $aWiringRotor_0_1 [12] ="M,O" $aWiringRotor_0_1 [13] ="N,W" $aWiringRotor_0_1 [14] ="O,Y" $aWiringRotor_0_1 [15] ="P,H" $aWiringRotor_0_1 [16] ="Q,X" $aWiringRotor_0_1 [17] ="R,U" $aWiringRotor_0_1 [18] ="S,S" $aWiringRotor_0_1 [19] ="T,P" $aWiringRotor_0_1 [20] ="U,A" $aWiringRotor_0_1 [21] ="V,I" $aWiringRotor_0_1 [22] ="W,B" $aWiringRotor_0_1 [23] ="X,R" $aWiringRotor_0_1 [24] ="Y,C" $aWiringRotor_0_1 [25] ="Z,J" $aWiringRotor_1_2 [0] = "A,P" ; Rotor 1 to 2 $aWiringRotor_1_2 [1] = "B,J" $aWiringRotor_1_2 [2] = "C,D" $aWiringRotor_1_2 [3] = "D,K" $aWiringRotor_1_2 [4] = "E,S" $aWiringRotor_1_2 [5] = "F,I" $aWiringRotor_1_2 [6] = "G,R" $aWiringRotor_1_2 [7] = "H,U" $aWiringRotor_1_2 [8] = "I,X" $aWiringRotor_1_2 [9] = "J,B" $aWiringRotor_1_2 [10] ="K,L" $aWiringRotor_1_2 [11] ="L,H" $aWiringRotor_1_2 [12] ="M,W" $aWiringRotor_1_2 [13] ="N,T" $aWiringRotor_1_2 [14] ="O,M" $aWiringRotor_1_2 [15] ="P,C" $aWiringRotor_1_2 [16] ="Q,Q" $aWiringRotor_1_2 [17] ="R,G" $aWiringRotor_1_2 [18] ="S,Z" $aWiringRotor_1_2 [19] ="T,N" $aWiringRotor_1_2 [20] ="U,A" $aWiringRotor_1_2 [21] ="V,Y" $aWiringRotor_1_2 [22] ="W,F" $aWiringRotor_1_2 [23] ="X,V" $aWiringRotor_1_2 [24] ="Y,O" $aWiringRotor_1_2 [25] ="Z,E" $aWiringRotor_2_3 [0] = "A,Y" ; Rotor 2 to 3 $aWiringRotor_2_3 [1] = "B,D" $aWiringRotor_2_3 [2] = "C,F" $aWiringRotor_2_3 [3] = "D,H" $aWiringRotor_2_3 [4] = "E,J" $aWiringRotor_2_3 [5] = "F,L" $aWiringRotor_2_3 [6] = "G,C" $aWiringRotor_2_3 [7] = "H,P" $aWiringRotor_2_3 [8] = "I,R" $aWiringRotor_2_3 [9] = "J,T" $aWiringRotor_2_3 [10] ="K,X" $aWiringRotor_2_3 [11] ="L,V" $aWiringRotor_2_3 [12] ="M,N" $aWiringRotor_2_3 [13] ="N,Z" $aWiringRotor_2_3 [14] ="O,B" $aWiringRotor_2_3 [15] ="P,E" $aWiringRotor_2_3 [16] ="Q,I" $aWiringRotor_2_3 [17] ="R,W" $aWiringRotor_2_3 [18] ="S,G" $aWiringRotor_2_3 [19] ="T,A" $aWiringRotor_2_3 [20] ="U,K" $aWiringRotor_2_3 [21] ="V,M" $aWiringRotor_2_3 [22] ="W,U" $aWiringRotor_2_3 [23] ="X,S" $aWiringRotor_2_3 [24] ="Y,Q" $aWiringRotor_2_3 [25] ="Z,O" $aWiringRotor_3_4 [0] = "A,K" ; Rotor 3 to 4 $aWiringRotor_3_4 [1] = "B,W" $aWiringRotor_3_4 [2] = "C,M" $aWiringRotor_3_4 [3] = "D,C" $aWiringRotor_3_4 [4] = "E,D" $aWiringRotor_3_4 [5] = "F,B" $aWiringRotor_3_4 [6] = "G,G" $aWiringRotor_3_4 [7] = "H,T" $aWiringRotor_3_4 [8] = "I,F" $aWiringRotor_3_4 [9] = "J,N" $aWiringRotor_3_4 [10] ="K,L" $aWiringRotor_3_4 [11] ="L,X" $aWiringRotor_3_4 [12] ="M,H" $aWiringRotor_3_4 [13] ="N,R" $aWiringRotor_3_4 [14] ="O,I" $aWiringRotor_3_4 [15] ="P,U" $aWiringRotor_3_4 [16] ="Q,Q" $aWiringRotor_3_4 [17] ="R,Y" $aWiringRotor_3_4 [18] ="S,A" $aWiringRotor_3_4 [19] ="T,J" $aWiringRotor_3_4 [20] ="U,Z" $aWiringRotor_3_4 [21] ="V,P" $aWiringRotor_3_4 [22] ="W,V" $aWiringRotor_3_4 [23] ="X,O" $aWiringRotor_3_4 [24] ="Y,S" $aWiringRotor_3_4 [25] ="Z,E" $aWiringRotor_4_5 [0] = "A,K" ; Rotor 4 to 5 $aWiringRotor_4_5 [1] = "B,X" $aWiringRotor_4_5 [2] = "C,E" $aWiringRotor_4_5 [3] = "D,F" $aWiringRotor_4_5 [4] = "E,O" $aWiringRotor_4_5 [5] = "F,Q" $aWiringRotor_4_5 [6] = "G,J" $aWiringRotor_4_5 [7] = "H,M" $aWiringRotor_4_5 [8] = "I,W" $aWiringRotor_4_5 [9] = "J,A" $aWiringRotor_4_5 [10] ="K,C" $aWiringRotor_4_5 [11] ="L,L" $aWiringRotor_4_5 [12] ="M,H" $aWiringRotor_4_5 [13] ="N,D" $aWiringRotor_4_5 [14] ="O,N" $aWiringRotor_4_5 [15] ="P,B" $aWiringRotor_4_5 [16] ="Q,S" $aWiringRotor_4_5 [17] ="R,U" $aWiringRotor_4_5 [18] ="S,Y" $aWiringRotor_4_5 [19] ="T,T" $aWiringRotor_4_5 [20] ="U,I" $aWiringRotor_4_5 [21] ="V,G" $aWiringRotor_4_5 [22] ="W,R" $aWiringRotor_4_5 [23] ="X,P" $aWiringRotor_4_5 [24] ="Y,Z" $aWiringRotor_4_5 [25] ="Z,V" $aWiringRotor_5_6 [0] = "A,S" ; Rotor 5 to 6 $aWiringRotor_5_6 [1] = "B,G" $aWiringRotor_5_6 [2] = "C,X" $aWiringRotor_5_6 [3] = "D,L" $aWiringRotor_5_6 [4] = "E,B" $aWiringRotor_5_6 [5] = "F,A" $aWiringRotor_5_6 [6] = "G,T" $aWiringRotor_5_6 [7] = "H,U" $aWiringRotor_5_6 [8] = "I,M" $aWiringRotor_5_6 [9] = "J,V" $aWiringRotor_5_6 [10] ="K,P" $aWiringRotor_5_6 [11] ="L,Q" $aWiringRotor_5_6 [12] ="M,W" $aWiringRotor_5_6 [13] ="N,N" $aWiringRotor_5_6 [14] ="O,J" $aWiringRotor_5_6 [15] ="P,K" $aWiringRotor_5_6 [16] ="Q,R" $aWiringRotor_5_6 [17] ="R,O" $aWiringRotor_5_6 [18] ="S,F" $aWiringRotor_5_6 [19] ="T,Y" $aWiringRotor_5_6 [20] ="U,Z" $aWiringRotor_5_6 [21] ="V,H" $aWiringRotor_5_6 [22] ="W,I" $aWiringRotor_5_6 [23] ="X,C" $aWiringRotor_5_6 [24] ="Y,D" $aWiringRotor_5_6 [25] ="Z,E" $aWiringRotor_6_7 [0] = "A,V" ; Rotor 7 to 8 $aWiringRotor_6_7 [1] = "B,W" $aWiringRotor_6_7 [2] = "C,T" $aWiringRotor_6_7 [3] = "D,J" $aWiringRotor_6_7 [4] = "E,Y" $aWiringRotor_6_7 [5] = "F,Q" $aWiringRotor_6_7 [6] = "G,E" $aWiringRotor_6_7 [7] = "H,Z" $aWiringRotor_6_7 [8] = "I,F" $aWiringRotor_6_7 [9] = "J,C" $aWiringRotor_6_7 [10] ="K,G" $aWiringRotor_6_7 [11] ="L,H" $aWiringRotor_6_7 [12] ="M,I" $aWiringRotor_6_7 [13] ="N,A" $aWiringRotor_6_7 [14] ="O,K" $aWiringRotor_6_7 [15] ="P,U" $aWiringRotor_6_7 [16] ="Q,L" $aWiringRotor_6_7 [17] ="R,M" $aWiringRotor_6_7 [18] ="S,S" $aWiringRotor_6_7 [19] ="T,B" $aWiringRotor_6_7 [20] ="U,D" $aWiringRotor_6_7 [21] ="V,N" $aWiringRotor_6_7 [22] ="W,X" $aWiringRotor_6_7 [23] ="X,P" $aWiringRotor_6_7 [24] ="Y,R" $aWiringRotor_6_7 [25] ="Z,O" $aWiringRotor_7_8 [0] = "A,E" ; Rotor 8 to 9 $aWiringRotor_7_8 [1] = "B,G" $aWiringRotor_7_8 [2] = "C,M" $aWiringRotor_7_8 [3] = "D,R" $aWiringRotor_7_8 [4] = "E,I" $aWiringRotor_7_8 [5] = "F,J" $aWiringRotor_7_8 [6] = "G,Q" $aWiringRotor_7_8 [7] = "H,A" $aWiringRotor_7_8 [8] = "I,N" $aWiringRotor_7_8 [9] = "J,O" $aWiringRotor_7_8 [10] ="K,W" $aWiringRotor_7_8 [11] ="L,X" $aWiringRotor_7_8 [12] ="M,Y" $aWiringRotor_7_8 [13] ="N,Z" $aWiringRotor_7_8 [14] ="O,U" $aWiringRotor_7_8 [15] ="P,V" $aWiringRotor_7_8 [16] ="Q,H" $aWiringRotor_7_8 [17] ="R,K" $aWiringRotor_7_8 [18] ="S,C" $aWiringRotor_7_8 [19] ="T,D" $aWiringRotor_7_8 [20] ="U,L" $aWiringRotor_7_8 [21] ="V,P" $aWiringRotor_7_8 [22] ="W,A" $aWiringRotor_7_8 [23] ="X,F" $aWiringRotor_7_8 [24] ="Y,S" $aWiringRotor_7_8 [25] ="Z,T" $aWiringRotor_8_9 [0] = "A,M" ; Rotor 9 to 10 $aWiringRotor_8_9 [1] = "B,N" $aWiringRotor_8_9 [2] = "C,G" $aWiringRotor_8_9 [3] = "D,B" $aWiringRotor_8_9 [4] = "E,C" $aWiringRotor_8_9 [5] = "F,D" $aWiringRotor_8_9 [6] = "G,H" $aWiringRotor_8_9 [7] = "H,I" $aWiringRotor_8_9 [8] = "I,Z" $aWiringRotor_8_9 [9] = "J,J" $aWiringRotor_8_9 [10] ="K,C" $aWiringRotor_8_9 [11] ="L,W" $aWiringRotor_8_9 [12] ="M,X" $aWiringRotor_8_9 [13] ="N,K" $aWiringRotor_8_9 [14] ="O,L" $aWiringRotor_8_9 [15] ="P,O" $aWiringRotor_8_9 [16] ="Q,P" $aWiringRotor_8_9 [17] ="R,A" $aWiringRotor_8_9 [18] ="S,Q" $aWiringRotor_8_9 [19] ="T,R" $aWiringRotor_8_9 [20] ="U,S" $aWiringRotor_8_9 [21] ="V,T" $aWiringRotor_8_9 [22] ="W,E" $aWiringRotor_8_9 [23] ="X,F" $aWiringRotor_8_9 [24] ="Y,U" $aWiringRotor_8_9 [25] ="Z,V" EndFunc ;==> InitialiseMachineSettings ; ================================== ; Func _GUI_closeOnEvent ( ) ; ================================== Func _GUI_closeOnEvent() GUIDelete() Exit 0 EndFunc ;==> _GUI_closeOnEvent
  2. While True Select Case $test = 1 do blabla .. If @error then ContinueLoop Else Exit 0 EndIf EndSelect WEnd as Far as i know there isn't something like RestartCase. But like i said you could wrap the Select statement into a Loop. See ContinueLoop ()
  3. HotKeySet ( "a", Quit ) Local $iValue While TRUE $iValue = Random (0, 9, 1) RestartCase () Sleep ( 100 ) WEnd Func RestartCase () Select Case $iValue = 1 ConsoleWrite ( "Value : " & $iValue & @CRLF ) Case $iValue = 7 ConsoleWrite ( "Value : " & $iValue & @CRLF ) EndSelect EndFunc ;==>RestartCase Func Quit () Exit 0 EndFunc ;==>Quit You could put the Select statement it in a While Loop or Do Until. Something like this.
  4. Just for fun. With only $string = "0.0.0000.123" and a LoopCount of 10.000 Times. @Pluto41 replacement took 0.648 Seconds to complete. @jguinch replacement took 0.093 Seconds to complete. @mikell replacement took 0.248 Seconds to complete. @jchd replacement took 0.148 Seconds to complete. @AndyG replacement took 0.168 Seconds to complete.
  5. #include <array.au3> ;Local $sInput = '0.0.0000.0123' ; 1 Test Input Local $sInput = '0.0.0000.123' ; 2 Test Input Local $aInput = StringSplit ( $sInput, "." ) If StringLen ( $aInput[ $aInput[0] ] ) = 3 Then $aInput[ $aInput[0] ] = "0" & $aInput[ $aInput[0] ] $aInput[ $aInput[0] ] = StringRegExpReplace($aInput[ $aInput[0] ], '(\d{2})(\d{2})', '$1.$2') Local $sNewResult = _ArrayToString ( $aInput, ".", 1 ) MsgBox (0, "New", $sNewResult ) Combination with StringSplit() and StringRegExpReplace() Unfortunately not a one-liner..
  6. After every event you have to read $aPos = WinGetPos ( $hGUI ) again. I can't see why that would work.. But i admit there is probably a better solution. I will follow the topic for other suggestions
  7. Func ChoosenRadio() If GUICtrlRead($idManAuth) = 1 Then $idCaption = ControlGetText("","",$idManAuth) GUICtrlCreateListViewItem($idCaption, $idTSList) GUICtrlSetState ( $idManAuth, $GUI_UNCHECKED ) ; ADDED You have found the solution yourself like Melba said. You could write a Func / Loop to uncheck all radio buttons or just add the GuiCtrlSetState ( see my code, last line.) after every ( if ) / ( elseIf () )
  8. #include <MsgBoxConstants.au3> Local $iPadding = 20 Local $mainUiHeight = 420 Local $mainUiWidth = 800 Local $hGUI = GUICreate ( "GUI", $mainUiWidth, $mainUiHeight, -1, -1 ) GUISetState (@SW_SHOW) ; Retrieve the position x, y and size (width and height) of the control Local $aPos = WinGetPos ( $hGUI ) ; Display the position and size of the edit control. MsgBox ( $MB_SYSTEMMODAL, "Parent $hGUI", "Position: " & $aPos[0] & ", " & $aPos[1] & @CRLF & "Size: " & $aPos[2] & ", " & $aPos[3] ) ; Test Input box within Parent Window ( $iPadding 20 ) Local $sAnswer = InputBox("Question", "Where were you born?", "Planet Earth", "", Default, Default, $aPos[0] + $iPadding, $aPos[1] + $iPadding, 0) Exit 0 I have not very much experience with this. (i never had any use for it). But the question sounds interesting and i think the answer can be useful for others too. Anyway i tried some things and the above code comes close to what you want. a bit weird is that $mainUiHeight / $mainUiWidth is not exactly the values represented by $aPos[]
  9. #include <array.au3> #include <MsgBoxConstants.au3> Local $sInput = 'Some Text Here' Local $sOutput = StringRegExpReplace($sInput, '(\w+)\s(\w+)\s(\w+)', '$3/$2/$1') Local $sMsg = StringFormat("Input:\t%s\n\nOutput:\t%s", $sInput, $sOutput) ; Result String MsgBox($MB_SYSTEMMODAL, "Result", $sMsg) Local $aNewArray = StringSplit ( $sOutput, "/" ) ; Result Array after StringSplit _ArrayDisplay ( $aNewArray, "New Array" ) Local $sFoo = $aNewArray [1] ; Result String assigning $aNewArray [element 1] to $sFoo Msgbox ($MB_SYSTEMMODAL, "Result", "$sFoo = " & $sFoo ) Perhaps using StringSplit ()
  10. Func getHDDNum() RunWait("gtSrNumHDD.bat") Sleep(100) Local $hddNum=FileReadLine("comp_id.txt",2) ConsoleWrite ("sr no is: "&$hddNum&@CRLF) MsgBox(0,"",$hddNum); ConsoleWrite ("sr no is: "&$hddNum&@CRLF) EndFunc getHDDNum() FileDelete("comp_id.txt") @ECHO Off vol c: > comp_id.txt Local $strDiskDrive = "C:" Local $objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2") ;Local $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_LogicalDisk Where DeviceID = 'C:'") Local $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_LogicalDisk Where DeviceID = '" & $strDiskDrive & "'" ) For $objItem In $colItems Local $strSerial = $objItem.VolumeSerialNumber ConsoleWrite ( "Serial Number of Drive " & $strDiskDrive & $strSerial & @CRLF ) Next @olmanRvr I changed Run to RunWait() in your'e function And In your'e batch file i changed the wmic command to: "Vol C: > comp_id.txt" After these changes the code seems to run ok. Also i added a third piece of code on how to do almost the same with WMI. Hope this helps
  11. Local $sProxyEnabled = RegRead ("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings", "ProxyEnable") If $sProxyEnabled <> 0 Then Local $sProxyServer = RegRead ("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings", "ProxyServer") If FileExist ( "C:\Temp\Output.txt" ) Then FileDelete ( "C:\Temp\Output.txt" ) FileWrite ("C:\Temp\Output.txt", $sProxyServer) Else Msgbox ( 0, "ProxyServer", "ProxyServer is not configured" ) EndIf Yup, FileWrite. Something like this.. See the help file for FileWrite / RegRead.
  12. ; This Local $WSHNetwork = ObjCreate("Wscript.Network") Local $sUsername = $WSHNetwork.UserName ConsoleWrite ( $sUsername ) #cs or this script ; Or this (script i had in my repository, not written by me ) #include <Array.au3> $un = _GetUsername() ;~ $un = StringLeft($un, stringlen($un) - 1) ; <-- The solution For $i = 1 To StringLen($un) $char = StringMid($un, $i, 1) ConsoleWrite(Asc($char) & " : >" & $char & "<" & @CRLF) Next $thing = StringLen($un) & " - 123" & String($un) & "456" ConsoleWrite(@CRLF & $thing & @CRLF) Func _GetUsername() Local $sUsername = "" Local $aResult = DllCall("Wtsapi32.dll", "int", "WTSQuerySessionInformationW", "int", 0, "dword", -1, "int", 5, "dword*", 0, "dword*", 0) If @error Or $aResult[0] = 0 Then Return SetError(1, 0, 0) Local $sUsername = BinaryToString(DllStructGetData(DllStructCreate("byte[" & $aResult[5] & "]", $aResult[4]), 1), 2) DllCall("Wtsapi32.dll", "int", "WTSFreeMemory", "ptr", $aResult[4]) Return $sUsername EndFunc ;==>_GetUsername #ce Perhaps its not such a good practise to "temporary" add a user to the local admin group.. Anyway hope this code helps.
  13. #include <MsgBoxConstants.au3> #include <StringConstants.au3> Local $sSearchDir = @UserProfileDir & "\Downloads\VIPRERescue*" ;Local $sSearchDir = "C:\Temp\Downloads\VIPRERescue*" Local $Drive = "C:\" do $hVipre = FileFindFirstFile($sSearchDir) Do $Vipre = FileFindNextFile($hVipre) If @Error Then Exitloop Until StringRegExp ( $Vipre, '(?i)VIPRERescue\d+.exe', $STR_REGEXPMATCH ) Until StringRegExp ( $Vipre, '(?i)VIPRERescue\d+.exe', $STR_REGEXPMATCH ) ConsoleWrite("Moving VipreRescue" & @CRLF) FileClose ($hVipre) FileMove(@UserProfileDir & "\Downloads\" & $Vipre, $Drive & "PortableApps\VIPRERescuePortable\App\VIPRERescue\VIPRERescue.exe", 1) This works for me in a test [c:\temp\..]. I think you are close to a solution for the problem.
  14. #include <MsgBoxConstants.au3> #include <StringConstants.au3> Local $sSearchDir = @UserProfileDir & "\Downloads\VIPRERescue*" Local $sFileName, $hSearch Do $hSearch = FileFindFirstFile ($sSearchDir) $sFileName = FileFindNextFile ($hSearch) FileClose ($hSearch) Sleep (500) Until StringRegExp ( $sFileName, '(?i)VIPRERescue\d+.exe', $STR_REGEXPMATCH ) ; Find VIPRERescue / Number / .exe Local $iResult = MsgBox (BitOR($MB_SYSTEMMODAL, $MB_OK), "Download complete", "File: " & $sFileName) Then Something like this? Added StringRegExp () Function.
  15. #include <MsgBoxConstants.au3> Local $sSearchDir = @UserProfileDir & "\Downloads\VIPRERescue.exe" Local $sSearchFile = "VIPRERescue.exe" Local $sFileName, $hSearch Do $hSearch = FileFindFirstFile ($sSearchDir & $sSearchFile) $sFileName = FileFindNextFile ($hSearch) Sleep (500) Until $sFileName = $sSearchFile FileClose ($hSearch) Local $iResult = MsgBox (BitOR($MB_SYSTEMMODAL, $MB_OK), "Download complete", "File: " & $sFileName) If the filename always is "VIPRERescue.exe" something like the code above would work. edit: Perhaps FileClose() should go in the Do / Until loop. I overlooked that.
×
×
  • Create New...