LordBlackout Posted April 13, 2011 Share Posted April 13, 2011 Hi all! I have a problem: I want to implement the One Time Pad Algorhitym in AutoIt, by XORing file's bits with key's bits. The problem is that I have no idea about reading single bits from a file.. any help? Thanks! Link to comment Share on other sites More sharing options...
jchd Posted April 13, 2011 Share Posted April 13, 2011 Lookup help for fileopen in binary mode. Read chunks of bytes, perform your xor and write. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
LordBlackout Posted April 13, 2011 Author Share Posted April 13, 2011 (edited) Hi, I tried FileOpen in binary mode, but the representation is not binary.. it contains 0-9 digits and some letters, I think is HEX.. Edited April 13, 2011 by LordBlackout Link to comment Share on other sites More sharing options...
jaberwacky Posted April 14, 2011 Share Posted April 14, 2011 Hex is another way of representing binary numbers. Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? Link to comment Share on other sites More sharing options...
LordBlackout Posted April 14, 2011 Author Share Posted April 14, 2011 Yes, I know, but how can I make the XOR with HEX? Is there a way to obtain single bits? Link to comment Share on other sites More sharing options...
jchd Posted April 14, 2011 Share Posted April 14, 2011 Open input in binary mode open output in binary mode read a byte if eof exitloop xor with corresponding byte in pad write result loop Hexadecimal is simply a "human-friendly" representation of data. You can display data in hex, octal, ASCII, UTF, whatever suits the need for you to comprehend it. Displaying data under one form or another doesn't change it but some forms give you a better understanding/readability. E.g. displaying text in hex isn't particularly easy to read. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
LordBlackout Posted April 14, 2011 Author Share Posted April 14, 2011 Thanks for the reply, but I don't understand a thing: Hex contains letters, that are not XORable.. Link to comment Share on other sites More sharing options...
jchd Posted April 14, 2011 Share Posted April 14, 2011 You really should google about things you don't understand. Look: say you have a file wich contents the string AB3. Ok this is one representation, suited to human eyes and brain. This ASCII string translates into hex as 41 42 33. This is a second representation, somehow less readable but your brain can still get it if you look at an ASCII table. In octal, you obtain 101 102 063. This is a fourth representation of the same string. Somehow unusual and much less readable. In binary, this is 01000001 01000010 00110011. This is a fourth representation of the very same data. Even if you can "read" the series of 0 and 1, it's now much harder to understand that these bits mean AB3. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
LordBlackout Posted April 14, 2011 Author Share Posted April 14, 2011 Thanks for the explanation, but is non this the thing that I don't understand.. I am googling but I can't find a solution: If I take a byte from a Hex string, let's say "A", how can I XOR this byte? (BitXOR doesn't XOR letters).. I could transform it in ASCII, but the variable number of digits is a problem when decoding.. Link to comment Share on other sites More sharing options...
iamtheky Posted April 14, 2011 Share Posted April 14, 2011 (edited) This ASCII string translates into hex as 41 42 33 so work with that $string = "AB3" $Sarray = stringsplit($string , "" , 2) for $i = 0 to ubound($Sarray) - 1 $bin = stringtrimleft(binary($Sarray[$i]) , 2) $Sarray[$i] = $bin Next $xor = BitXOR($Sarray[0] , $Sarray[1] , $Sarray[2]) msgbox (0, '' , $Xor) Edited April 14, 2011 by iamtheky ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
LordBlackout Posted April 14, 2011 Author Share Posted April 14, 2011 (edited) Thanks, following your example I tried this: $ID = FileOpen($File, 16) $File = StringSplit(StringToBinary(StringTrimLeft(FileRead($ID), 2)), "") FileClose($ID) $ID = FileOpen($Chiave, 16) $Chiave = StringSplit(StringToBinary(StringTrimLeft(FileRead($ID), 2)), "") FileClose($ID) If $Chiave[0] < $File[0] Then MsgBox(16, "Errore", "La chiave è troppo corta.") Else For $a = 3 To $File[0] Step 1 $File[$a] = BitXOR($File[$a], $Chiave[$a]) Next $File = "0x" & BinaryToString(_ArrayToString($File, "", 1)) $ID = FileOpen($NewFile, 18) FileWrite($ID, $File) MsgBox(64, "Info", "Operazione completata con successo.") EndIf But doesn't work.. the file isn't decrypted and becomes unreadable. Edited April 14, 2011 by LordBlackout Link to comment Share on other sites More sharing options...
jaberwacky Posted April 16, 2011 Share Posted April 16, 2011 0 1 2 3 4 5 6 7 8 9 A B C D E F A = 10 B = 11 C = 12 D = 13 E = 14 F = 15 Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? 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