<commit_before>package client.encry;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;

import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;

import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;

import client.res.ClientConst;
import client.util.ClientUtils;

/**
 *  Űȯ ̷ Ŭ
 * 
 * @author 
 *
 */
public class KeyExchangeClient {

	private BufferedInputStream bis;
	private BufferedOutputStream bos;

	private int readCount;
	private int dataSize;
	private int bodyLength;
	//    DES256 Ű
	private String desKey = null;
	private String cipherKey;

	private byte[] pubKey;
	private byte[] privKey;
	private byte[] receiveKey;
	private byte[] header;

	public KeyExchangeClient(BufferedInputStream bis, BufferedOutputStream bos) {
		this.bis = bis;
		this.bos = bos;
	}

	public void initialize() {
		try {
			RSAKeyGen encKey = new RSAKeyGen();
			pubKey = encKey.getPublicKey();
			privKey = encKey.getPrivateKey();
		} catch (Throwable e) {
			System.out.println(e.getMessage());
			// RSA Ű 
		}
	}

	/**
	 * 
	 * @param index
	 *            ε 1 :  RSA Ű Ҷ 
	 *            ε 2 : Ű ȯ ̷ Hello World ׽Ʈ
	 * @throws IOException
	 * @throws InvalidKeyException
	 * @throws NoSuchAlgorithmException
	 * @throws NoSuchPaddingException
	 * @throws InvalidAlgorithmParameterException
	 * @throws IllegalBlockSizeException
	 * @throws BadPaddingException
	 */
	private void sendToServer(int index) throws IOException {
		String msgEncryString = null;

		if (index == 1) {
			msgEncryString = ClientUtils.makeJSONMessageForEncry(EncryUtils.byteArrayToHex(pubKey), new JSONObject(),
					new JSONObject());
		}
		// Ű ȯ ̷ ȣȭ ׽Ʈ
		else if (index == 2) {
			msgEncryString = ClientUtils.makeJSONMessageForEncry(AESUtils.AES_Encode("Hello World", desKey),
					new JSONObject(), new JSONObject());
		}

		byte[] msgEncryByte = ClientUtils.makeMessageStringToByte(
				new byte[ClientConst.HEADER_LENTH + msgEncryString.getBytes(ClientConst.CHARSET).length],
				msgEncryString);
		bos.write(msgEncryByte);
		bos.flush();

	}

	/**
	 * 
	 * @param index
	 *            ε 1 : κ RSA Ű ȣȭ DES256 Ű  
	 *            ε 2 : κ Hello World ׽Ʈ   
	 * @throws IOException
	 * @throws BadPaddingException
	 * @throws IllegalBlockSizeException
	 * @throws InvalidAlgorithmParameterException
	 * @throws NoSuchPaddingException
	 * @throws NoSuchAlgorithmException
	 * @throws InvalidKeyException
	 */
	private void receiveForServer(int index) throws IOException {
		readCount = bis.read(header);
		dataSize = ClientUtils.byteToInt(header);
		byte[] body = new byte[dataSize];
		bodyLength = bis.read(body);

		if (index == 1) {
			cipherKey = ClientUtils.parseEncryMessage(new JSONParser(), new String(body, ClientConst.CHARSET));
		} else if (index == 2) {
			String msg = ClientUtils.parseEncryMessage(new JSONParser(), new String(body, ClientConst.CHARSET));
			// Ϳ  Ͱ ٸٸ Űȯ  ִٰ Ǵϴ
			// ʿϴ.
		}

	}

	private void decryptionDes256Key() {
		try {
			receiveKey = EncryUtils.hexToByteArray(cipherKey);
			RSADecryption rd = new RSADecryption(receiveKey, privKey);
			desKey = rd.getDESkey();
			System.out.println("AESŰ : "+desKey);
		} catch (InvalidKeyException | IllegalBlockSizeException | BadPaddingException | NoSuchAlgorithmException
				| NoSuchProviderException | NoSuchPaddingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public String start() {
		try {
			//  
			header = new byte[ClientConst.HEADER_LENTH];
			// Ű  ʱȭ
			initialize();
			//  RSA Ű 
			sendToServer(1);
			//   RSA Ű ȣȭ DES256 Ű 
			receiveForServer(1);
			// ȣȭ DES256 Ű ȣȭ
			decryptionDes256Key();
			// Hello World ȣ 
			sendToServer(2);
			// Hello World ȣ  ޱ
			receiveForServer(2);
		} catch (IOException e) {
			System.out.println(e.getMessage());
		} catch (Throwable e) {
			System.out.println(e.getMessage());
			// desŰ  
		}
		return desKey;
	}

}
<commit_msg>commit<commit_after>package client.encry;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;

import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;

import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;

import client.res.ClientConst;
import client.util.ClientUtils;

/**
 *  Űȯ ̷ Ŭ
 * 
 * @author 
 *
 */
public class KeyExchangeClient {

	private BufferedInputStream bis;
	private BufferedOutputStream bos;

	private int readCount;
	private int dataSize;
	private int bodyLength;
	//    DES256 Ű
	private String desKey = null;
	private String cipherKey;

	private byte[] pubKey;
	private byte[] privKey;
	private byte[] receiveKey;
	private byte[] header;

	public KeyExchangeClient(BufferedInputStream bis, BufferedOutputStream bos) {
		this.bis = bis;
		this.bos = bos;
	}

	public void initialize() {
		try {
			RSAKeyGen encKey = new RSAKeyGen();
			pubKey = encKey.getPublicKey();
			privKey = encKey.getPrivateKey();
		} catch (Throwable e) {
			System.out.println(e.getMessage());
			// RSA Ű 
		}
	}

	/**
	 * 
	 * @param index
	 *            ε 1 :  RSA Ű Ҷ 
	 *            ε 2 : Ű ȯ ̷ Hello World ׽Ʈ
	 * @throws IOException
	 * @throws InvalidKeyException
	 * @throws NoSuchAlgorithmException
	 * @throws NoSuchPaddingException
	 * @throws InvalidAlgorithmParameterException
	 * @throws IllegalBlockSizeException
	 * @throws BadPaddingException
	 */
	private void sendToServer(int index) throws IOException {
		String msgEncryString = null;

		if (index == 1) {
			msgEncryString = ClientUtils.makeJSONMessageForEncry(EncryUtils.byteArrayToHex(pubKey), new JSONObject(),
					new JSONObject());
			System.out.println(msgEncryString);
		}
		// Ű ȯ ̷ ȣȭ ׽Ʈ
		else if (index == 2) {
			msgEncryString = ClientUtils.makeJSONMessageForEncry(AESUtils.AES_Encode("Hello World", desKey),
					new JSONObject(), new JSONObject());
		}

		byte[] msgEncryByte = ClientUtils.makeMessageStringToByte(
				new byte[ClientConst.HEADER_LENTH + msgEncryString.getBytes(ClientConst.CHARSET).length],
				msgEncryString);
		bos.write(msgEncryByte);
		bos.flush();

	}

	/**
	 * 
	 * @param index
	 *            ε 1 : κ RSA Ű ȣȭ DES256 Ű  
	 *            ε 2 : κ Hello World ׽Ʈ   
	 * @throws IOException
	 * @throws BadPaddingException
	 * @throws IllegalBlockSizeException
	 * @throws InvalidAlgorithmParameterException
	 * @throws NoSuchPaddingException
	 * @throws NoSuchAlgorithmException
	 * @throws InvalidKeyException
	 */
	private void receiveForServer(int index) throws IOException {
		readCount = bis.read(header);
		dataSize = ClientUtils.byteToInt(header);
		byte[] body = new byte[dataSize];
		bodyLength = bis.read(body);

		if (index == 1) {
			cipherKey = ClientUtils.parseEncryMessage(new JSONParser(), new String(body, ClientConst.CHARSET));
		} else if (index == 2) {
			String msg = ClientUtils.parseEncryMessage(new JSONParser(), new String(body, ClientConst.CHARSET));
			// Ϳ  Ͱ ٸٸ Űȯ  ִٰ Ǵϴ
			// ʿϴ.
		}

	}

	private void decryptionDes256Key() {
		try {
			receiveKey = EncryUtils.hexToByteArray(cipherKey);
			RSADecryption rd = new RSADecryption(receiveKey, privKey);
			desKey = rd.getDESkey();
			System.out.println("AESŰ : "+desKey);
		} catch (InvalidKeyException | IllegalBlockSizeException | BadPaddingException | NoSuchAlgorithmException
				| NoSuchProviderException | NoSuchPaddingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public String start() {
		try {
			//  
			header = new byte[ClientConst.HEADER_LENTH];
			// Ű  ʱȭ
			initialize();
			//  RSA Ű 
			sendToServer(1);
			//   RSA Ű ȣȭ DES256 Ű 
			receiveForServer(1);
			// ȣȭ DES256 Ű ȣȭ
			decryptionDes256Key();
			// Hello World ȣ 
			sendToServer(2);
			// Hello World ȣ  ޱ
			receiveForServer(2);
		} catch (IOException e) {
			System.out.println(e.getMessage());
		} catch (Throwable e) {
			System.out.println(e.getMessage());
			// desŰ  
		}
		return desKey;
	}

}

{'fraction_non_alphanumeric': 0.10618946373730215, 'fraction_numerical': 0.007087172218284904, 'mean_word_length': 3.711741791875348, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6531256', 'n_tokens_mistral': 3164, 'n_tokens_neox': 2727, 'n_words': 637}