diff --git a/netty/src/main/java/com/ljsd/jieling/netty/cocdex/Tea.java b/netty/src/main/java/com/ljsd/jieling/netty/cocdex/Tea.java index da645b6da..797e765d5 100644 --- a/netty/src/main/java/com/ljsd/jieling/netty/cocdex/Tea.java +++ b/netty/src/main/java/com/ljsd/jieling/netty/cocdex/Tea.java @@ -65,37 +65,41 @@ public class Tea { return result; } - //加密 - public static byte[] encrypt(byte[] content, int offset, int[] key, int times) {//times为加密轮数 - int[] tempInt = byteToIntArray(content, offset); - int y = tempInt[0], z = tempInt[1], sum = 0, i; - int delta = 0x9e3779b9; //这是算法标准给的值 - int a = key[0], b = key[1], c = key[2], d = key[3]; - for (i = 0; i < times; i++) { - sum += delta; - y += ((z << 4) + a) ^ (z + sum) ^ ((z >> 5) + b); - z += ((y << 4) + c) ^ (y + sum) ^ ((y >> 5) + d); + //加密 + public static byte[] encrypt(byte[] content, int offset, int[] key, int times){//times为加密轮数 + int[] tempInt = byteToIntArray(content, offset); + int delta=0x9e3779b9; //这是算法标准给的值 + int a = key[0], b = key[1], c = key[2], d = key[3]; + for(int m=0; m>5) + b); + z += ((y<<4) + c) ^ (y + sum) ^ ((y>>5) + d); + } + tempInt[m]=y; + tempInt[m+1]=z; } - tempInt[0] = y; - tempInt[1] = z; return intArrayToByte(tempInt, 0); } - //解密 - public static byte[] decrypt(byte[] encryptContent, int offset, int[] key, int times) { + public static byte[] decrypt(byte[] encryptContent, int offset, int[] key, int times){ int[] tempInt = byteToIntArray(encryptContent, offset); - int y = tempInt[0], z = tempInt[1], sum = 0xC6EF3720, i; int delta = 0x9e3779b9; //这是算法标准给的值 int a = key[0], b = key[1], c = key[2], d = key[3]; - for (i = 0; i < times; i++) { - z -= ((y << 4) + c) ^ (y + sum) ^ ((y >> 5) + d); - y -= ((z << 4) + a) ^ (z + sum) ^ ((z >> 5) + b); - sum -= delta; + for(int m=0; m> 5) + d); + y -= ((z << 4) + a) ^ (z + sum) ^ ((z >> 5) + b); + sum -= delta; + } + tempInt[m] = y; + tempInt[m+1] = z; } - tempInt[0] = y; - tempInt[1] = z; return intArrayToByte(tempInt, 0); }