I have a working script in python like this:
How can I convert the while loop into for loop?
I have AutoIT script like this:
I want to convert my while loop into for loop
or I simply want to convert my for loop from AutoIT to Python
How to do that?
Thank You
Code:
import re
handle_file1 = open("example1.so", "rb")
hex_file1 = handle_file1.read().hex().upper()
handle_file1.close()
handle_file2 = open("example2.so", "rb")
hex_file2 = handle_file2.read().hex().upper()
handle_file2.close()
array_file1 = re.findall('[0-9A-Fa-f]{2}', hex_file1)
array_file2 = re.findall('[0-9A-Fa-f]{2}', hex_file2)
i = 0
while i < len(array_file1):
if array_file1[i] != array_file2[i]:
if i % 4 == 0:
print(array_file1[i] + array_file1[i + 1] + array_file1[i + 2] + array_file1[i + 3] + "\t" + array_file2[i] + array_file2[i + 1] + array_file2[i + 2] + array_file2[i + 3])
i += 4
elif i % 4 == 1:
print(array_file1[i - 1] + array_file1[i] + array_file1[i + 1] + array_file1[i + 2] + "\t" + array_file2[i - 1] + array_file2[i] + array_file2[i + 1] + array_file2[i + 2])
i += 3
elif i % 4 == 2:
print(array_file1[i - 2] + array_file1[i - 1] + array_file1[i] + array_file1[i + 1] + "\t" + array_file2[i - 2] + array_file2[i - 1] + array_file2[i] + array_file2[i + 1])
i += 2
elif i % 4 == 3:
print(array_file1[i - 3] + array_file1[i - 2] + array_file1[i - 1] + array_file1[i] + "\t" + array_file2[i - 3] + array_file2[i - 2] + array_file2[i - 1] + array_file2[i])
i += 1
else:
i += 1
How can I convert the while loop into for loop?
I have AutoIT script like this:
Code:
For $i = 1 To UBound($aFile1, $UBOUND_ROWS)-1
If $aFile1[$i] <> $aFile2[$i] Then
If Mod($i, 4) = 0 Then
FileWrite(@ScriptDir & '\' & 'Result.txt', $aFile1[$i] & ' ' & $aFile1[$i+1] & ' ' & $aFile1[$i+2] & ' ' & $aFile1[$i+3] & ' ' & $aFile2[$i] & ' ' & $aFile2[$i+1] & ' ' & $aFile2[$i+2] & ' ' & $aFile2[$i+3] & @CRLF)
$i = $i + 4
ElseIf Mod($i, 4) = 1 Then
FileWrite(@ScriptDir & '\' & 'Result.txt', $aFile1[$i-1] & ' ' & $aFile1[$i] & ' ' & $aFile1[$i+1] & ' ' & $aFile1[$i+2] & ' ' & $aFile2[$i-1] & ' ' & $aFile2[$i] & ' ' & $aFile2[$i+1] & ' ' & $aFile2[$i+2] & @CRLF)
$i = $i + 3
ElseIf Mod($i, 4) = 2 Then
FileWrite(@ScriptDir & '\' & 'Result.txt', $aFile1[$i-2] & ' ' & $aFile1[$i-1] & ' ' & $aFile1[$i] & ' ' & $aFile1[$i+1] & ' ' & $aFile2[$i-2] & ' ' & $aFile2[$i-1] & ' ' & $aFile2[$i] & ' ' & $aFile2[$i+1] & @CRLF)
$i = $i + 2
ElseIf Mod($i, 4) = 3 Then
FileWrite(@ScriptDir & '\' & 'Result.txt', $aFile1[$i-3] & ' ' & $aFile1[$i-2] & ' ' & $aFile1[$i-1] & ' ' & $aFile1[$i] & ' ' & $aFile2[$i-3] & ' ' & $aFile2[$i-2] & ' ' & $aFile2[$i-1] & ' ' & $aFile2[$i] & @CRLF)
$i = $i + 1
EndIf
ElseIf $aFile1[$i] = $aFile2[$i] Then
ContinueLoop
EndIf
Next
I want to convert my while loop into for loop
or I simply want to convert my for loop from AutoIT to Python
How to do that?
Thank You