Tsukihime Posted May 25, 2011 Share Posted May 25, 2011 BinaryToString works nicely, except the binary string I have needs to be decrypted first. This is the algorithm 1: BitXOR the string with FF mask 2: binaryToString the result 3: now I have a human-readable string Except I'm stuck on the first part. I can't come up with a way to split the binary value into an array of bytes so that I can XOR each byte and convert to string. Any ideas? Link to comment Share on other sites More sharing options...
PsaltyDS Posted May 25, 2011 Share Posted May 25, 2011 BinaryMid() in a loop on BinaryLen() Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Tsukihime Posted May 25, 2011 Author Share Posted May 25, 2011 Great, I got an array representing the decrypted characters. Now I tried _arrayToString, but all I get is the first letter. That's odd... Link to comment Share on other sites More sharing options...
UEZ Posted May 25, 2011 Share Posted May 25, 2011 (edited) You mean something like this?: #include <Array.au3> #include <String.au3> $e = Encode("This is a secret text!") ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $e = ' & $e & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console $d = Decode($e) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $d = ' & $d & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console Func Encode($text, $xor = 0xFF) Local $aASCII = StringToASCIIArray($text), $i For $i = 0 To UBound($aASCII) - 1 $aASCII[$i] = Hex(BitXOR(Hex($aASCII[$i], 2), $xor), 2) Next Return StringToBinary(_ArrayToString($aASCII, "")) EndFunc Func Decode($bString, $xor = 0xFF) Local $sCoded = BinaryToString($bString) Local $aASCII = StringRegExp($sCoded, ".{0,1}\S", 3) Local $s For $i = 0 To UBound($aASCII) - 1 $s &= Chr(Dec(BitXOR("0x" & $aASCII[$i], $xor))) Next Return $s EndFunc Br, UEZ Edited May 25, 2011 by 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!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
Tsukihime Posted May 27, 2011 Author Share Posted May 27, 2011 (edited) I am confused about something. Here's a simple script that inverts a "k" and writes out to a file $outFile = FileOpen("test", 18) $start = StringtoBinary("k") $inverted = BitXOR($start, 0xFF) FileWrite($outFile, chr($inverted)) However, in the file I get 81 instead of the 94 that I expected. I tried this on two different computers and on one of them, it was 94. On the other, it was 81. If I just say $outFile = FileOpen("test", 18) $start = StringtoBinary("k") FileWrite($outFile, chr($start)) It says 6B, as expected. I thought maybe I had to convert it to hex, so I also tried $outFile = FileOpen("test", 18) $start = StringtoBinary("k") $inverted = hex(BitXOR($start, 0xFF)) FileWrite($outFile, chr($inverted)) But this time it gave me 5E I expect an inverted "k" to be 94, but for some reason it's not working. Edited May 27, 2011 by Tsukihime Link to comment Share on other sites More sharing options...
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