<commit_before>package de.st_ddt.crazylogin.crypt;

import java.lang.reflect.InvocationTargetException;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;

import org.bukkit.configuration.ConfigurationSection;

import de.st_ddt.crazylogin.LoginPlugin;
import de.st_ddt.crazylogin.data.LoginData;
import de.st_ddt.crazyplugin.exceptions.CrazyCommandException;
import de.st_ddt.crazyplugin.exceptions.CrazyException;

public final class EncryptHelper
{

	private static final Map<String, Class<? extends Encryptor>> encryptors = new TreeMap<String, Class<? extends Encryptor>>(String.CASE_INSENSITIVE_ORDER);

	protected EncryptHelper()
	{
		super();
	}

	public static Encryptor getEncryptor(final LoginPlugin<? extends LoginData> plugin, final ConfigurationSection config)
	{
		if (config == null)
			return null;
		final String algorithm = config.getString("name");
		Class<? extends Encryptor> clazz = null;
		if (algorithm != null)
			clazz = encryptors.get(algorithm.toLowerCase());
		if (clazz == null)
		{
			final String type = config.getString("type");
			if (type != null)
				try
				{
					clazz = Class.forName(type).asSubclass(Encryptor.class);
				}
				catch (final ClassNotFoundException e)
				{}
		}
		if (clazz == null)
			return null;
		try
		{
			return clazz.getConstructor(LoginPlugin.class, ConfigurationSection.class).newInstance(plugin, config);
		}
		catch (final Exception e)
		{
			e.printStackTrace();
			return null;
		}
	}

	/**
	 * Required for updating Encryptor names in new Version!
	 */
	public static Encryptor getEncryptor(final LoginPlugin<? extends LoginData> plugin, final String algorithm, final ConfigurationSection config)
	{
		final Class<? extends Encryptor> clazz = encryptors.get(algorithm.toLowerCase());
		if (clazz == null)
			return null;
		try
		{
			return clazz.getConstructor(LoginPlugin.class, ConfigurationSection.class).newInstance(plugin, config);
		}
		catch (final Exception e)
		{
			e.printStackTrace();
			return null;
		}
	}

	public static Encryptor getEncryptor(final LoginPlugin<? extends LoginData> plugin, final String algorithm, final String[] args) throws CrazyException
	{
		final Class<? extends Encryptor> clazz = encryptors.get(algorithm.toLowerCase());
		if (clazz == null)
			return null;
		try
		{
			return clazz.getConstructor(LoginPlugin.class, String[].class).newInstance(plugin, args);
		}
		catch (final InvocationTargetException e)
		{
			final Throwable t = e.getCause();
			if (t instanceof CrazyCommandException)
				((CrazyCommandException) t).addCommandPrefix(algorithm);
			if (t instanceof CrazyException)
				throw (CrazyException) t;
			e.printStackTrace();
			return null;
		}
		catch (final Exception e)
		{
			e.printStackTrace();
			return null;
		}
	}

	public static void registerAlgorithm(final String algorithm, final Class<? extends Encryptor> clazz)
	{
		encryptors.put(algorithm.toLowerCase(), clazz);
	}

	public static Set<String> getAlgorithms()
	{
		return encryptors.keySet();
	}

	public static String byteArrayToHexString(final byte... args)
	{
		final StringBuilder res = new StringBuilder();
		final String[] chars = new String[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f" };
		for (final byte arg : args)
		{
			res.append(chars[(arg >> 4) + 16]);
			res.append(chars[arg % 16 + 16]);
		}
		return res.toString();
	}
}<commit_msg>Speed up byteArrayToHexString method (8 times)<commit_after>package de.st_ddt.crazylogin.crypt;

import java.lang.reflect.InvocationTargetException;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;

import org.bukkit.configuration.ConfigurationSection;

import de.st_ddt.crazylogin.LoginPlugin;
import de.st_ddt.crazylogin.data.LoginData;
import de.st_ddt.crazyplugin.exceptions.CrazyCommandException;
import de.st_ddt.crazyplugin.exceptions.CrazyException;

public final class EncryptHelper
{

	private static final char[] CRYPTCHARS = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
	private static final Map<String, Class<? extends Encryptor>> encryptors = new TreeMap<String, Class<? extends Encryptor>>(String.CASE_INSENSITIVE_ORDER);

	protected EncryptHelper()
	{
		super();
	}

	public static Encryptor getEncryptor(final LoginPlugin<? extends LoginData> plugin, final ConfigurationSection config)
	{
		if (config == null)
			return null;
		final String algorithm = config.getString("name");
		Class<? extends Encryptor> clazz = null;
		if (algorithm != null)
			clazz = encryptors.get(algorithm.toLowerCase());
		if (clazz == null)
		{
			final String type = config.getString("type");
			if (type != null)
				try
				{
					clazz = Class.forName(type).asSubclass(Encryptor.class);
				}
				catch (final ClassNotFoundException e)
				{}
		}
		if (clazz == null)
			return null;
		try
		{
			return clazz.getConstructor(LoginPlugin.class, ConfigurationSection.class).newInstance(plugin, config);
		}
		catch (final Exception e)
		{
			e.printStackTrace();
			return null;
		}
	}

	/**
	 * Required for updating Encryptor names in new Version!
	 */
	public static Encryptor getEncryptor(final LoginPlugin<? extends LoginData> plugin, final String algorithm, final ConfigurationSection config)
	{
		final Class<? extends Encryptor> clazz = encryptors.get(algorithm.toLowerCase());
		if (clazz == null)
			return null;
		try
		{
			return clazz.getConstructor(LoginPlugin.class, ConfigurationSection.class).newInstance(plugin, config);
		}
		catch (final Exception e)
		{
			e.printStackTrace();
			return null;
		}
	}

	public static Encryptor getEncryptor(final LoginPlugin<? extends LoginData> plugin, final String algorithm, final String[] args) throws CrazyException
	{
		final Class<? extends Encryptor> clazz = encryptors.get(algorithm.toLowerCase());
		if (clazz == null)
			return null;
		try
		{
			return clazz.getConstructor(LoginPlugin.class, String[].class).newInstance(plugin, args);
		}
		catch (final InvocationTargetException e)
		{
			final Throwable t = e.getCause();
			if (t instanceof CrazyCommandException)
				((CrazyCommandException) t).addCommandPrefix(algorithm);
			if (t instanceof CrazyException)
				throw (CrazyException) t;
			e.printStackTrace();
			return null;
		}
		catch (final Exception e)
		{
			e.printStackTrace();
			return null;
		}
	}

	public static void registerAlgorithm(final String algorithm, final Class<? extends Encryptor> clazz)
	{
		encryptors.put(algorithm.toLowerCase(), clazz);
	}

	public static Set<String> getAlgorithms()
	{
		return encryptors.keySet();
	}

	public static String byteArrayToHexString(final byte... args)
	{
		final char[] chars = new char[args.length * 2];
		for (int i = 0; i < args.length; i++)
		{
			chars[i * 2] = CRYPTCHARS[(args[i] >> 4) & 0xF];
			chars[i * 2 + 1] = CRYPTCHARS[(args[i]) & 0xF];
		}
		return new String(chars);
	}
}
{'fraction_non_alphanumeric': 0.12967473850121794, 'fraction_numerical': 0.006591202177962459, 'mean_word_length': 4.336391437308868, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '365311', 'n_tokens_mistral': 2497, 'n_tokens_neox': 2243, 'n_words': 583}