From bb9eb4b64f0848cb98258394749a0010d9c51aba Mon Sep 17 00:00:00 2001 From: leebj Date: Fri, 25 Oct 2024 10:36:10 +0900 Subject: [PATCH] =?UTF-8?q?=EC=86=8C=EC=8A=A4=20=EC=A0=95=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cokr/xit/base/crypto/bean/Delphi.java | 33 +++++++----- .../cokr/xit/base/crypto/bean/XitBridge.java | 53 ++++++++----------- 2 files changed, 43 insertions(+), 43 deletions(-) diff --git a/src/main/java/cokr/xit/base/crypto/bean/Delphi.java b/src/main/java/cokr/xit/base/crypto/bean/Delphi.java index a8d6710..3f7bb9b 100644 --- a/src/main/java/cokr/xit/base/crypto/bean/Delphi.java +++ b/src/main/java/cokr/xit/base/crypto/bean/Delphi.java @@ -6,8 +6,8 @@ import java.nio.ByteOrder; /** * @author leebj */ -class Delphi { - static int move(byte[] source, int sourceFrom){ +interface Delphi { + default int move(byte[] source, int sourceFrom){ byte[] b = new byte[4]; b[0] = source[sourceFrom]; b[1] = source[sourceFrom+1]; @@ -17,7 +17,7 @@ class Delphi { return _bytesToInt_le(b); } - static void move(int sourceInt, byte[] target, int targetFrom){ + default void move(int sourceInt, byte[] target, int targetFrom){ byte[] source = _intToBytes_le(sourceInt); int j = targetFrom; @@ -27,7 +27,7 @@ class Delphi { } } - static void move(byte[] source, int sourceFrom, byte[] target, int targetFrom, int size){ + default void move(byte[] source, int sourceFrom, byte[] target, int targetFrom, int size){ int i = sourceFrom; int j = targetFrom; for(int z=0; z < size; z++) { @@ -37,27 +37,36 @@ class Delphi { } } - static void move(byte[] source, int sourceFrom, int[] targetIntArray, int size){ + default void move(byte[] source, int sourceFrom, int[] targetIntArray, int size){ byte[] byteTarget = new byte[targetIntArray.length]; move(source,sourceFrom,byteTarget,0,size); _convertIntArray(byteTarget, targetIntArray); } - static void move(int[] sourceIntArray, byte[] target, int targetFrom, int size){ + default void move(int[] sourceIntArray, byte[] target, int targetFrom, int size){ byte[] byteSource = new byte[sourceIntArray.length]; _convertByteArray(sourceIntArray, byteSource); move(byteSource,0,target,targetFrom,size); } - static int inc(int num, int incNum) { + default int inc(int num, int incNum) { return num + incNum; } - static byte[] setLength(int len) { + default byte[] setLength(int len) { return new byte[len]; } - private static void _convertIntArray(byte[] b, int[] n){ + default void _convertIntArray(int[] n){ + for(int j = 0; j < n.length; j++ ) { + if(n[j] < 0) + n[j] = n[j] + 256; + else + n[j] = n[j]; + } + } + + default void _convertIntArray(byte[] b, int[] n){ for(int j = 0; j < b.length; j++ ) { if(b[j] < 0) n[j] = b[j] + 256; @@ -66,17 +75,17 @@ class Delphi { } } - private static void _convertByteArray(int[] n, byte[] b){ + default void _convertByteArray(int[] n, byte[] b){ for(int j = 0; j < n.length; j++ ) { b[j] = (byte)n[j]; } } - private static byte[] _intToBytes_le(int num) { + default byte[] _intToBytes_le(int num) { return ByteBuffer.allocate(4).order(ByteOrder.LITTLE_ENDIAN).putInt(num).array(); } - private static int _bytesToInt_le(byte[] byteArray) { + default int _bytesToInt_le(byte[] byteArray) { return ByteBuffer.wrap(byteArray).order(ByteOrder.LITTLE_ENDIAN).getInt(); } } \ No newline at end of file diff --git a/src/main/java/cokr/xit/base/crypto/bean/XitBridge.java b/src/main/java/cokr/xit/base/crypto/bean/XitBridge.java index 7b41af2..a0d139c 100644 --- a/src/main/java/cokr/xit/base/crypto/bean/XitBridge.java +++ b/src/main/java/cokr/xit/base/crypto/bean/XitBridge.java @@ -11,7 +11,7 @@ import cokr.xit.foundation.AbstractComponent; /** * @author leebj */ -public class XitBridge extends AbstractComponent { +public class XitBridge extends AbstractComponent implements Delphi { private int[] masterKey = new int[32]; private int keySize; private String @@ -323,7 +323,7 @@ public class XitBridge extends AbstractComponent { hash = inMD5(key = value); } - Delphi.move(hash, 0, masterKey, hash.length); + move(hash, 0, masterKey, hash.length); } catch (Exception e) { throw runtimeException(e); } @@ -384,13 +384,13 @@ public class XitBridge extends AbstractComponent { encryptSize = value_byte.length; if(version == 1) { - encryptData = Delphi.setLength(encryptSize); - Delphi.move(value_byte,0,encryptData,0,encryptSize); + encryptData = setLength(encryptSize); + move(value_byte,0,encryptData,0,encryptSize); } else { - encryptData = Delphi.setLength(encryptSize + 4); - Delphi.move(encryptSize, encryptData, 0); - Delphi.move(value_byte,0,encryptData,4,encryptSize); + encryptData = setLength(encryptSize + 4); + move(encryptSize, encryptData, 0); + move(value_byte,0,encryptData,4,encryptSize); } @@ -401,20 +401,20 @@ public class XitBridge extends AbstractComponent { start = 1; if(version == 1) { - cryptData = Delphi.setLength(dataSize); + cryptData = setLength(dataSize); } else { - cryptData = Delphi.setLength(dataSize + 16 - (dataSize % 16)); + cryptData = setLength(dataSize + 16 - (dataSize % 16)); } for(i = 1; i <= Math.floorDiv(dataSize,16); i++) { Arrays.fill(inBlock, 0); Arrays.fill(outBlock, 0); - Delphi.move(encryptData, start-1, inBlock, 16); + move(encryptData, start-1, inBlock, 16); doEncrypt(inBlock, roundNum, roundKey, outBlock); - Delphi.move(outBlock,cryptData,start-1,16); + move(outBlock,cryptData,start-1,16); - start = Delphi.inc(start,16); + start = inc(start,16); } //나머지크기 @@ -422,9 +422,9 @@ public class XitBridge extends AbstractComponent { Arrays.fill(inBlock, 0); Arrays.fill(outBlock, 0); - Delphi.move(encryptData,start-1,inBlock,modSize); + move(encryptData,start-1,inBlock,modSize); doEncrypt(inBlock, roundNum, roundKey, outBlock); - Delphi.move(outBlock,cryptData,start-1,16); + move(outBlock,cryptData,start-1,16); } if(encode) { @@ -464,16 +464,16 @@ public class XitBridge extends AbstractComponent { roundNum = decKeySetup(masterKey, roundKey); start = 1; - encryptData = Delphi.setLength(dataSize); + encryptData = setLength(dataSize); for (i = 1; i <= Math.floorDiv(dataSize, 16); i++) { Arrays.fill(inBlock, 0); Arrays.fill(outBlock, 0); - Delphi.move(cryptData,(start-1),inBlock,16); + move(cryptData,(start-1),inBlock,16); doEncrypt(inBlock, roundNum, roundKey, outBlock); - Delphi.move(outBlock,encryptData,start-1,16); + move(outBlock,encryptData,start-1,16); - start = Delphi.inc(start,16); + start = inc(start,16); } @@ -481,9 +481,9 @@ public class XitBridge extends AbstractComponent { Arrays.fill(inBlock, 0); Arrays.fill(outBlock, 0); - Delphi.move(cryptData,(start-1),inBlock,16); + move(cryptData,(start-1),inBlock,16); doEncrypt(inBlock, roundNum, roundKey, outBlock); - Delphi.move(outBlock,encryptData,start-1,16); + move(outBlock,encryptData,start-1,16); } @@ -498,9 +498,9 @@ public class XitBridge extends AbstractComponent { return new String(encryptData, charset); } else { - encryptSize = Delphi.move(encryptData,0); + encryptSize = move(encryptData,0); byte[] copy = new byte[encryptSize]; - Delphi.move(encryptData,4,copy,0,encryptSize); + move(encryptData,4,copy,0,encryptSize); return new String(copy, charset); } @@ -509,15 +509,6 @@ public class XitBridge extends AbstractComponent { } } - private static void _convertIntArray(int[] n){ - for(int j = 0; j < n.length; j++ ) { - if(n[j] < 0) - n[j] = n[j] + 256; - else - n[j] = n[j]; - } - } - private static int[][] SBox = { // S-box type 1 {