| 1 | package utils; |
| 2 | |
| 3 | public class tool { |
| 4 | |
| 5 | public static long bytesToLong(byte[] bytes) { |
| 6 | long num = 0; |
| 7 | int len = bytes.length; |
| 8 | for (int ix = 0; ix < 8; ++ix) { |
| 9 | num <<= 8; |
| 10 | num |= (bytes[len - ix - 1] & 0xff); |
| 11 | } |
| 12 | return num; |
| 13 | } |
| 14 | |
| 15 | public static byte[] longToBytes(long num) { |
| 16 | byte[] byteNum = new byte[8]; |
| 17 | for (int ix = 0; ix < 8; ++ix) { |
| 18 | int offset = 64 - (ix + 1) * 8; |
| 19 | byteNum[ix] = (byte) ((num >> offset) & 0xff); |
| 20 | } |
| 21 | return byteNum; |
| 22 | } |
| 23 | |
| 24 | public static boolean Xor_Empty(byte[] xor) { |
| 25 | for (int i = 0; i < xor.length; i++) { |
| 26 | if (xor[i] == 0) { |
| 27 | continue; |
| 28 | } else |
| 29 | return false; |
| 30 | } |
| 31 | return true; |
| 32 | } |
| 33 | |
| 34 | |
| 35 | public static byte[] Xor(byte[] x, byte[] y) { |
| 36 | int min =0; |
| 37 | if(x.length>y.length){ |
| 38 | min = y.length; |
| 39 | }else{ |
| 40 | min = x.length; |
| 41 | } |
| 42 | byte[] temp = new byte[min]; |
| 43 | for (int i = 0; i < min; i++) { |
| 44 | temp[i] = (byte) (x[i] ^ y[i]); |
| 45 | } |
| 46 | return temp; |
| 47 | } |
| 48 | } |
nothing calls this directly
no outgoing calls
no test coverage detected