help with <<<< operator to c

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have some c++ code I'm trying to convert to c. I think >>>> is byte shifting but no idea what >>> is. This is the original code also I think byte is specificity to c++ I'd need char myByte[] I think.

 

private final long initialValue=0xC541A9;
	private final byte[] challenge={0,0,0,'t','e','s','t','0'};
	private final long v1=0x109028;
	private final long v2=0xFFEF6FD7;

	private byte[] calculateKey(byte[] seedBytes) {
		challenge[0]=seedBytes[0];
		challenge[1]=seedBytes[1];
		challenge[2]=seedBytes[2];

		long buffer=initialValue;

		for (int i = 0; i < challenge.length; i++) {
			int b=challenge[i]&0xff;

			for (int j = 0; j < 8; j++) {
				long tempBuffer=0;
				if((b&1)!=(buffer&1)){
					buffer|=0x1000000;
					tempBuffer=v1;
				}

				b>>>=1;

				tempBuffer^=buffer>>>1;
				tempBuffer&=v1;
				tempBuffer|=v2&(buffer>>>1);

				buffer=tempBuffer&0xffffff;
			}
		}

		byte[] key={
				(byte)(buffer>>>(4)&0xff),
				(byte)((buffer>>>(20)&0x0f)+(buffer>>>(8)&0xf0)),
				(byte)((buffer<<(4)&0xff)+(buffer>>>(16)&0x0f)),
		};

		return key;
	}
Last Edited: Thu. Apr 21, 2016 - 01:39 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

It's a java unsigned bitshift operator.  I think.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

S_K_U_N_X wrote:
I have some c++ code ... 

 

Rezer wrote:
 It's ... java ... 

 

Clearly, the essential first step here is to be certain which language it actually is!

 

Then look up a reference book or site for that language.

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

yeah Rezer cleared that up for me. I ran the code in a java compiler and the seedBytes elements can't be over 128. Too much over head converting this so going to abandon it.