Sign in to follow this  
Followers 0
Monica

BitXOR function

3 posts in this topic

Hi,

I'm writing a script for encrypt / decrypt data file :)

The function _StringEncrypt is too slow and unusable for byte data.

So I'm writing a simple XOR encrypting function, but the embedded BitXOR not works fine... what's wrong??

1 $file2read = FileOpen("c:\test.txt", 16)

2 $file2write = FileOpen("c:\test_encrypted.txt", 16+2)

3 $temp = FileRead($file2read, 1) ; read only the first char in this example

4 $result = BitXOR($temp, 1) ; i want to do the xor operation between the number 1 and $temp

5 FileWrite($file2write, $result)

6 FileClose($file2read)

7 FileClose($file2write)

When line 4 is executed, $result contains 4 character (byte) insted 1: the first is (correctly) the XOR result; the others are a NULL chars! Why?

Regards, sorry for my bad engl...

Monica from Italy

;)

Share this post


Link to post
Share on other sites

I've written a few encryption algorithms in AutoIt, so lets see if I can help you. The BitXOR function only works on numbers currently, signed, 32-bit integers to be exact, so just trying to feed all the text-file input into it like that won't quite work.

In order to do what you want, you'll need to convert from the Binary that you read in to a number (some form of Hex() or Dec() usually works).

Now, as to whether or not you should do this, I can't really say. BitXOR with just a 1 (probably just an example, I hope) isn't the most secure encryption method. If you want, have a look at the Cryptography Suite post in the example scripts section. Someone else in there made a BitXOR encryption function already, as well as RC4, and I try to maintain the rijndael/AES, DES, and blowfish algorithms myself. If you need an example as to why this won't work, I'll be happy to try to help you out.

Share this post


Link to post
Share on other sites

BitXOR works fine, it's just an annoyance of AutoIt's binary data type and binary file write mode, which automatically assumes 32 bits for ints and 64bits for floats, and doesn't let you specify.

Instead of

$result = BitXOR($temp, 1)

do

$result = Binary("0x" & Hex(BitXOR($temp, 1), 2))


"be smart, drink your wine"

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0