prbmjr Member Licensed User Apr 21, 2021 #1 Hi everyone, I must implement a XOR operation between arrays of bytes, because I need to implement a special data encryption requeted by my client.. I found only the bit.xor function between integers, Is there a way to implement a XOR with arrays? Thank you in advance! br, Paulo Bueno
Hi everyone, I must implement a XOR operation between arrays of bytes, because I need to implement a special data encryption requeted by my client.. I found only the bit.xor function between integers, Is there a way to implement a XOR with arrays? Thank you in advance! br, Paulo Bueno
prbmjr Member Licensed User Apr 21, 2021 #2 For reference, it would be a function like numpy.bitwise_xor (python) - https://numpy.org/doc/stable/refere....html?highlight=bitwise_xor#numpy.bitwise_xor Upvote 0
For reference, it would be a function like numpy.bitwise_xor (python) - https://numpy.org/doc/stable/refere....html?highlight=bitwise_xor#numpy.bitwise_xor
Erel B4X founder Staff member Licensed User Longtime User Apr 22, 2021 #3 Code: Copy Sub ArrayXor (b1() As Byte, b2() As Byte) As Byte() 'assuming that the arrays are with the same length Dim b3(b1.Length) As Byte For i = 0 To b1.Length - 1 b3(i) = Bit.Xor(b1(i), b2(i)) Next Return b3 End Sub Upvote 0
Code: Copy Sub ArrayXor (b1() As Byte, b2() As Byte) As Byte() 'assuming that the arrays are with the same length Dim b3(b1.Length) As Byte For i = 0 To b1.Length - 1 b3(i) = Bit.Xor(b1(i), b2(i)) Next Return b3 End Sub
prbmjr Member Licensed User Apr 22, 2021 #4 Erel said: Code: Copy Sub ArrayXor (b1() As Byte, b2() As Byte) As Byte() 'assuming that the arrays are with the same length Dim b3(b1.Length) As Byte For i = 0 To b1.Length - 1 b3(i) = Bit.Xor(b1(i), b2(i)) Next Return b3 End Sub Click to expand... Hi Erel, Thank you very much for your answer. I had something like this already implemented, but my concern is about the performance, if I have to use this type of code instead a real function/library using big arrays, like 500k, 50mb, etc... These arrays are entires files that must be encrypted... I have a similar code in python for reference and this runs really fast using the function numpy.bitwise_xor . I will try and I let you know with the result. br, Paulo Bueno Upvote 0
Erel said: Code: Copy Sub ArrayXor (b1() As Byte, b2() As Byte) As Byte() 'assuming that the arrays are with the same length Dim b3(b1.Length) As Byte For i = 0 To b1.Length - 1 b3(i) = Bit.Xor(b1(i), b2(i)) Next Return b3 End Sub Click to expand... Hi Erel, Thank you very much for your answer. I had something like this already implemented, but my concern is about the performance, if I have to use this type of code instead a real function/library using big arrays, like 500k, 50mb, etc... These arrays are entires files that must be encrypted... I have a similar code in python for reference and this runs really fast using the function numpy.bitwise_xor . I will try and I let you know with the result. br, Paulo Bueno
Erel B4X founder Staff member Licensed User Longtime User Apr 22, 2021 #5 Test it. Code: Copy Dim b1(500000), b2(500000) As Byte For i = 1 To 100 Dim n As Long = DateTime.Now ArrayXor(b1, b2) Log(DateTime.Now - n) Next On my device it takes between 0 to 1 millisecond. Upvote 0
Test it. Code: Copy Dim b1(500000), b2(500000) As Byte For i = 1 To 100 Dim n As Long = DateTime.Now ArrayXor(b1, b2) Log(DateTime.Now - n) Next On my device it takes between 0 to 1 millisecond.
prbmjr Member Licensed User Apr 22, 2021 #6 Erel said: Test it. Code: Copy Dim b1(500000), b2(500000) As Byte For i = 1 To 100 Dim n As Long = DateTime.Now ArrayXor(b1, b2) Log(DateTime.Now - n) Next On my device it takes between 0 to 1 millisecond. Click to expand... Hi Erel, I tested with this code: B4X: Copy Sub ArrayXor_teste As Byte() 'assuming that the arrays are with the same length Dim b1(552643), b2(552643) As Byte Dim b3(b1.Length) As Byte For i = 0 To b1.Length - 1 b3(i) = Bit.Xor(b1(i), b2(i)) Next Return b3 End Sub In my test I used a Sansung S8 device and takes 32 seg, why?? Upvote 0
Erel said: Test it. Code: Copy Dim b1(500000), b2(500000) As Byte For i = 1 To 100 Dim n As Long = DateTime.Now ArrayXor(b1, b2) Log(DateTime.Now - n) Next On my device it takes between 0 to 1 millisecond. Click to expand... Hi Erel, I tested with this code: B4X: Copy Sub ArrayXor_teste As Byte() 'assuming that the arrays are with the same length Dim b1(552643), b2(552643) As Byte Dim b3(b1.Length) As Byte For i = 0 To b1.Length - 1 b3(i) = Bit.Xor(b1(i), b2(i)) Next Return b3 End Sub In my test I used a Sansung S8 device and takes 32 seg, why??
DonManfred Expert Licensed User Longtime User Apr 22, 2021 #7 prbmjr said: In my test I used a Sansung S8 device and takes 32 seg, why?? Click to expand... Did you tested it in RELEASE mode?? NEVER do performance measures in DEBUG mode. Last edited: Apr 22, 2021 Upvote 0
prbmjr said: In my test I used a Sansung S8 device and takes 32 seg, why?? Click to expand... Did you tested it in RELEASE mode?? NEVER do performance measures in DEBUG mode.
prbmjr Member Licensed User Apr 22, 2021 #8 DonManfred said: Did you tested it in RELEASE mode?? NEVER do performance messures in DEBUG mode. Click to expand... Hi, No, In debug mode, I will test in release mode now... Thank you! Upvote 0
DonManfred said: Did you tested it in RELEASE mode?? NEVER do performance messures in DEBUG mode. Click to expand... Hi, No, In debug mode, I will test in release mode now... Thank you!
DonManfred Expert Licensed User Longtime User Apr 22, 2021 #9 i did a quick test in one app of mine. As the app does other things in parallel too i got 135ms as result. Still FAST; 0,135 Seconds. Upvote 0
i did a quick test in one app of mine. As the app does other things in parallel too i got 135ms as result. Still FAST; 0,135 Seconds.
prbmjr Member Licensed User Apr 22, 2021 #10 DonManfred said: i did a quick test in one app of mine. As the app does other things in parallel too i got 135ms as result. Still FAST; 0,135 Seconds. Click to expand... Hi, I tested in release mode and all process is quite fast now.. Upvote 0
DonManfred said: i did a quick test in one app of mine. As the app does other things in parallel too i got 135ms as result. Still FAST; 0,135 Seconds. Click to expand... Hi, I tested in release mode and all process is quite fast now..