LordBlackout Posted November 8, 2011 Posted November 8, 2011 Hi, I'm working on a File Crypter and I have a problem: I read the file in binary mode but I can't XOR the bytes with the key because they're displayed in HEX. How can I display the file's data in true binary, made of 1 and 0? Thank you very much, Lord_Blackout
Matrix112 Posted November 8, 2011 Posted November 8, 2011 Maybe this will help you, copied from Help File Local $var = Binary("0x00204060") ;$var is the binary type msgbox(0, "IsBinary", IsBinary($var))
LordBlackout Posted November 8, 2011 Author Posted November 8, 2011 Yes but I need to read the file obtaining a string made of 0 and 1... in your example the variable type is "Binary", but it isn't displayed as 0 and 1..
UEZ Posted November 10, 2011 Posted November 10, 2011 Try this: #include <Constants.au3> Global Const $sInFile = @ScriptDir & "test.txt" Global Const $sOutFile = @ScriptDir & "Test.crypt" CryptFile($sInFile, $sOutFile) MsgBox(0, "Encrypt", FileRead($sOutFile)) MsgBox(0, "Decrypt", CryptFile($sOutFile, "")) Func CryptFile($sInFile, $sOutFile, $XOR = 0xFF) ;coded by UEZ 2011 Local $hFile = FileOpen($sInFile, 16) If $hFile = -1 Then Return SetError(1, @error, 0) Local $i = 0 If Not FileSetPos($hFile, $i, $FILE_BEGIN) Then Return SetError(2, @error, 0) Local $crypt While 1 $char = FileRead($hFile, 1) If @error = -1 Then ExitLoop $crypt &= Hex(BitXOR($char, $XOR), 2) $i += 1 FileSetPos($hFile, $i, $FILE_BEGIN) WEnd FileClose($hFile) If $sOutFile = "" Then Return BinaryToString("0x" & $crypt) $hFile = FileOpen($sOutFile, 18) If $hFile = -1 Then Return SetError(3, @error, 0) FileWrite($hFile, Binary("0x" & $crypt)) FileClose($hFile) EndFunc Br, UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
ProgAndy Posted November 11, 2011 Posted November 11, 2011 It is possible to use BitXOR with binary data $XOR = 0xFFFFFFFF $sFile = @ScriptDir & "test.txt" $sOutFile = $sFile & ".xored" $hFile = FileOpen($sFile, 16) $bOutput = Binary("") While 1 $bRead = FileRead($hFile, 4) If @error Then ExitLoop ElseIf BinaryLen($bRead) < 4 Then $bOutput &= BinaryMid(Binary(BitXOR($bRead, $XOR)), 1, BinaryLen($bRead)) Else $bOutput &= Binary(BitXOR($bRead, $XOR)) EndIf WEnd FileClose($hFile) $hFile = FileOpen($sOutFile, 18) FileWrite($hFile, $bOutput) FileClose($hFile) *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now