How can i XOR these two numbers?
조회 수: 4 (최근 30일)
이전 댓글 표시
I have 2 sets of values: X =
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
U =
01011000
11100010
11111100
11001110
11111010
01111110
00110000
01100001
00110110
01111111
00011101
01010111
10100100
11100111
01000101
01011010
I want to XOR X and U.
I tried value=xor(X-'0',U-'1');
But i got an error. What must I do?
댓글 수: 3
Jan
2017년 10월 24일
편집: Jan
2017년 10월 24일
@Darsana P: No, it doesn't. It would work only if the inputs are char vectors:
X = '11100010';
But if X is a numerical vector already, subtracting '0' is meaningless. Subtracting '1' is not useful at all. In other words: "- '0'" is used to convert a char vector containing digits to a numerical vector containing the corresponding numbers.
Copying some code, which you do not understand, is guessing. Guessing is not useful for programming. You can check, what you are doing easily:
X - '0'
U - '1'
The result looks weird, doesn't it? But this works directly:
X = [1 1 1 0 0 0 1 0];
U = [0 0 0 0 0 0 0 0];
val = xor(X, U);
Well, xor'ing with zeros is not that interesting.
채택된 답변
Jan
2017년 10월 24일
편집: Jan
2017년 10월 24일
What are the types of X and U? Are they double or char vectors? Please post the input, such that it can be used by copy&paste.
X = [0; 0; 1] ;
U = [0 1 0 1 1 0 0 0; ...
1 1 1 0 0 0 1 0; ...
1 1 1 1 1 1 0 0];
Result = [U(:, 1:end-1), xor(X, U(:, end))]
Or perhaps:
X = ['0'; '0'; '1'] ;
U = ['01011000'; ...
'11100010'; ...
'11111100'];
Xd = X - '0'; % Convert CHAR '01' to DOUBLE [0, 1]
Ud = X - '0';
Result = [Ud(:, 1:end-1), xor(Xd, Ud(:, end))]
It would be easier to find a solution if you explain, what you want as result.
댓글 수: 3
Jan
2017년 10월 24일
@Darsana P M: This is still no valid Matlab code. What does
U =[01011000
11100010]; % Abbreviated
mean? Numbers do not have leading zeros. So perhaps this is a char matrix?
U =['01011000'; ...
'11100010'];
The quotes are really important here. Or perhaps you mean a numerical matrix:
U =[0 1 0 1 1 0 0 0; ...
1 1 1 0 0 0 1 0];
I still assume that your problem is based on a confusion of the types. So please concentrate on this detail.
{'00', '00'} is a very strange input for an AES encryption. Perhaps these are HEX numbers? It is much easier to let AES operate on bytes, UINT8 arrays. Because the bit pattern is completely mixed by this encryption, operating with bit matrices (in which type ever) seems odd here.
추가 답변 (1개)
KSSV
2017년 10월 24일
X = [0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1] ;
U =[01011000
11100010
11111100
11001110
11111010
01111110
00110000
01100001
00110110
01111111
00011101
01010111
10100100
11100111
01000101
01011010] ;
res = xor(num2str(X),num2str(U))
참고 항목
카테고리
Help Center 및 File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!