Results 1 to 14 of 14
Thread: How to XOR
- 09-14-2008, 12:58 PM #1
Member
- Join Date
- Sep 2008
- Posts
- 9
- Rep Power
- 0
- 09-14-2008, 01:43 PM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Convert two variable in to bit number and XOR. Nothing more that that.
JVM do the XOR operation for you. So what's your question here?byte x = 12; // 0000 1100
byte y = 10; // 0000 1010
System.out.println(x ^ y); // 0000 0110
- 09-15-2008, 06:48 PM #3
Member
- Join Date
- Sep 2008
- Posts
- 9
- Rep Power
- 0
Hi,
thx, but am new to java.
how to convert to bit??
i have 2 byte variables, and one is smalest than the other , so it should be padded with 0.
regards
- 09-15-2008, 08:23 PM #4
What do you mean convert to bit? Possible you wish to print the individual bits, but we need to know what it is you want to end up with and why.
Just studies is ok answer, could be several things.Introduction to Programming Using Java.
Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor
- 09-15-2008, 08:24 PM #5
Senior Member
- Join Date
- Aug 2008
- Posts
- 384
- Rep Power
- 5
You don't need to randa, java does it for you.
I die a little on the inside...
Every time I get shot.
- 09-15-2008, 08:24 PM #6
Senior Member
- Join Date
- Aug 2008
- Posts
- 384
- Rep Power
- 5
But else you could use String.toByteArray() (I think)
I die a little on the inside...
Every time I get shot.
- 09-16-2008, 04:40 AM #7
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
- 09-16-2008, 06:21 PM #8
Member
- Join Date
- Sep 2008
- Posts
- 9
- Rep Power
- 0
Hi,
Eranga, your code returns : operator ^ cannot be applied to java.lang.string.byte
so....
i have 2 byte[] var to XOR , the result should be returned as byte[]
i tried converting to string , to have a sequence of 1s and 0s
it didn't work.
rgrds
- 09-16-2008, 06:40 PM #9
Please post the full text of the error message.
Also post your code.
Your descriptions don't say what the code does.
What is that? In java class names start with Uppercase letters.java.lang.string.byte
- 09-16-2008, 07:42 PM #10
Member
- Join Date
- Sep 2008
- Posts
- 9
- Rep Power
- 0
i've tried eranga's peice of code.
it returned operator ^ cannot be applied to java.lang.String.byte
- 09-16-2008, 07:46 PM #11
some ideas .....
Java Code:/** * This code is a discussion of an opinion in a technical form. * There is no legitimate derivite use, and is known to be flawed. * Reader assumes the risk, of any kind and nature, in any time and place, * without burden of proof of jurisdition nor Snake Oil Certificate of Military Grade Encryption. */ import java.security.SecureRandom; class QuestionDemo { private static byte[] BeuafordsBytes;// // Dem darn demos, oh what a yo-yo! SecureRandom random = SecureRandom.getInstance("SHA1PRNG"); BeaufordsBytes = random.generateSeed(2); // xor operations here as directed by poster.... Byte FirstBite = new Byte(BeaufordsBytes [0]);// Byte SecondBite = new Byte(BeaufordsBytes [2]);// PhoneHomeMessage phm = new PhoneHomeMessage(FirstByte.toString());// phm.addData(SecondByte.toString());// Internet.releaseNewSoftware(phm);// EasyMoney.rakeItIn();//Introduction to Programming Using Java.
Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor
- 09-16-2008, 08:10 PM #12
Member
- Join Date
- Sep 2008
- Posts
- 9
- Rep Power
- 0
this is the piece of code am working on
.........
byte[] entete2=new byte[12];
System.arraycopy(entete,0,entete2,0,entete.length) ;
System.arraycopy(bb,0,entete2,8,4);
messagesize=12+HEdatalength+HEdatalength2+cipherRn d.length;
smessage=new byte[messagesize];
System.arraycopy(entete2,0,smessage,0,entete2.leng th);
System.arraycopy(HE1,0,smessage,entete2.length,HE1 .length);
System.arraycopy(HE2,0,smessage,(entete2.length+HE 1.length),HE2.length);
System.arraycopy(cipherRnd,0,smessage,(entete2.len gth+HE1.length+HE2.length),cipherRnd.length);
at this point,i have to call a function with 2 parameters similar to smessage.
the function should apply the XOr and returns a byte [] value
i'll work on the code u provided
thx
- 09-16-2008, 11:58 PM #13
When you get error messages, copy and paste the FULL text here. DO NOT EDIT them.operator ^ cannot be applied to java.lang.String.byte
Your piece of code doesn't show why the ^ operator doesn't work.
Where is the code that Eranga showed you? It does an XOR on two bytes. If the bytes are in an array change the example to:
Given: byte[] b1 and byte[] b2
byte xorB = b1[i] ^ b2[i];
- 09-17-2008, 04:31 AM #14
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Yes, please sen your code here to see. In my code segment there is no any issues. May be you are using in wrong way. Sen the full code to see.


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks