You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
BITXOR OPERATION
3 views (last 30 days)
Show older comments
Hello I want to do the "bitxor" operation as shown in below code. But since bitxor takes only 2 arguments the following code gives ERROR. Please suggest a solution. Mail me at lokesh_jolly05@yahoo.co.in
L(3*(i-1)+1)=mod(bitxor(B1(3*(i-1)+1),uint64(mod((abs(X(i))-floor(abs(X(i))))*10^14,256)),256));
3 Comments
LOKESH
on 27 Dec 2011
I receive the following error for bitxor:
"??? Error using ==> bitxor
Inputs must be unsigned integers of the same class or scalar
doubles."
Please suggest solution.
How to do that?or should I partition the above formulae?
Accepted Answer
Walter Roberson
on 26 Dec 2011
You have a bracket misplaced.
L(3*(i-1)+1)=mod(bitxor(B1(3*(i-1)+1),uint64(mod((abs(X(i))-floor(abs(X(i))))*10^14,256))),256);
Notice the ')' after 256 was moved to the end of the previous argument.
15 Comments
Walter Roberson
on 27 Dec 2011
What datatype is B1 ? The uint64() around the second argument is forcing that argument to be unsigned 64 bit integers, so if B1 is not also unsigned 64 bit integers, you have a problem.
mod((abs(X(i))-floor(abs(X(i))))*10^14,256) appears likely to be floating point number in the range 0 to (256 minus epsilon) . Converted to a 64 bit unsigned integer is going to have the effect of rounding that value, leading to results in the range 0 to 256 inclusive. Is that what you want, that you would normally be working with the bottom 8 bits only but that on occasion you would instead be working with the 9th bit only (256 exactly) ?
Walter Roberson
on 27 Dec 2011
What does class(B1) indicate? If it is a grayscale image such as you indicate, it is almost certainly not unsigned 64 bit integer. It might plausibly be unsigned 8 bit integer, or unsigned 16 bit integer, or double precision.
What is your intention with the code? What is it that you want that section of code to do?
LOKESH
on 28 Dec 2011
THE CODE is used to just to shuffle the image.
The B1 is a grayscale image & to protect the image three parameters X,Y & Z are calculated. Then the BitXOR is done to get final image.
The code looks as below:
L=zeros(M,M);
for i=1:(M^2/3-1)
L(3*(i-1)+1)=mod(bitxor(B1(3*(i-1)+1),uint64(mod((abs(X(i))-floor(abs(X(i))))*10^14,256))),256);
L(3*(i-1)+2)=mod(bitxor(B1(3*(i-1)+2),uint64(mod((abs(Y(i))-floor(abs(Y(i))))*10^14,256))),256);
L(3*(i-1)+3)=mod(bitxor(B1(3*(i-1)+3),uint64(mod((abs(Z(i))-floor(abs(Z(i))))*10^14,256))),256);
end;
where M is size of B1 image. What can be B1 image-unsigned 8, 16 or double --How to know that?
Any other solution or suggestion?
Thanks in advance!!
Walter Roberson
on 28 Dec 2011
class(B1)
will tell you what the datatype is.
Walter Roberson
on 29 Dec 2011
I pointed out above that in some cases, it could end up being the 9th bit you are attempting to modify -- unless there is something in the way that X and Y and Z are calculated that prevents that. Altering the 9th bit of 8 is going to be trouble...
You have not shown us any code involving Y so we cannot advise you as to what the problem is for it.
LOKESH
on 29 Dec 2011
for i=1:(M)
%L(3*(i-1)+1)= mod(bitxor(B(3*(i-1)+1),unit64(mod(abs(X(i)-floor(abs(X(i)),256)*10^14)),256);
L(3*(i-1)+1)=mod(bitxor(B1(3*(i-1)+1),uint8(mod((abs(X(i))-floor(abs(X(i))))*10^14,256))),256);
L(3*(i-1)+2)=mod(bitxor(B1(3*(i-1)+2),uint8(mod((abs(Y(i))-floor(abs(Y(i))))*10^14,256))),256);
L(3*(i-1)+3)=mod(bitxor(B1(3*(i-1)+3),uint8(mod((abs(Z(i))-floor(abs(Z(i))))*10^14,256))),256);
end;
Reference:A Chaotic Image Encryption
Katherine Struss,2009
Walter Roberson
on 29 Dec 2011
How about showing us the code that computes X and the code that computes Y... if, that is, you are still hoping for feedback from us as to why Y is the length it is.
Walter Roberson
on 31 Dec 2011
The Mathematica code constructs and uses X, Y, and Z up to position index length^2/3, which is array location number length^2/3+1 (because Mathematica uses 0 based indexing). Your MATLAB code constructs X, Y, and Z up to position 200 (fixed number), but then tries to use up to M^2/3-1.
I thought that in the past I had seen that Mathematica was able to generate MATLAB code from Mathematica code. If that is correct, it would probably be better to use that conversion than to convert it yourself -- or to at least use the automated conversion for comparison.
Walter Roberson
on 1 Jan 2012
http://library.wolfram.com/infocenter/MathSource/577/
More Answers (0)
See Also
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)