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

Jan
Jan 2011년 12월 26일
Please post the error message.
LOKESH
LOKESH 2011년 12월 27일
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?
LOKESH
LOKESH 2011년 12월 27일
B1 is image, rest are the parameters going in a for loop.

댓글을 달려면 로그인하십시오.

 채택된 답변

Walter Roberson
Walter Roberson 2011년 12월 26일

0 개 추천

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

LOKESH
LOKESH 2011년 12월 27일
Thanks Walter.
But now 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
Walter Roberson
Walter Roberson 2011년 12월 27일
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) ?
LOKESH
LOKESH 2011년 12월 27일
B1 is image, rest are the parameters going in a for loop.
LOKESH
LOKESH 2011년 12월 27일
B1 is a grayscale image after some opearions.
While X(i) parameters are based on equations involving Numerical methods.
Walter Roberson
Walter Roberson 2011년 12월 27일
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
LOKESH 2011년 12월 28일
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
Walter Roberson 2011년 12월 28일
class(B1)
will tell you what the datatype is.
LOKESH
LOKESH 2011년 12월 29일
it is unit 8,but now i receive ERROR:
??? Attempted to access Y(201); index out of bounds because
numel(Y)=200.
Also I would like to know that is the "i" loop termination parameters ok-->M^2/3-1
Walter Roberson
Walter Roberson 2011년 12월 29일
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
LOKESH 2011년 12월 29일
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
Walter Roberson 2011년 12월 29일
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
Walter Roberson 2011년 12월 31일
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.
LOKESH
LOKESH 2012년 1월 1일
I know that such conversion is possible.Do you have nay idea about it,i am unable to get any conversion S/W or toolbox?
Walter Roberson
Walter Roberson 2012년 1월 1일
http://library.wolfram.com/infocenter/MathSource/577/
LOKESH
LOKESH 2012년 1월 14일
how to use the Mathemtica to matlab Expression converter as i have Matlab 2010Ra & Mathematica v 8.
I need to convert the following expressions into matlab:
B=Flatten[B];
L=partition[L,length];
Any solution

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by