<commit_before>package net._95point2.fpe;

import java.math.BigInteger;
import java.util.Random;

import org.junit.Assert;
import org.junit.Test;

import net._95point2.fpe.FPE;

public class FPETests 
{
	@Test
	public void testBasic() throws Exception
	{
		final byte[] key = "Here is my secret key!".getBytes();
	    final byte[] tweak = "tweak".getBytes();
	    final int range = 100;
		final BigInteger modulus = BigInteger.valueOf(range);
		
		BigInteger plain = BigInteger.valueOf(53);
		BigInteger enc = FPE.encrypt(modulus, plain, key, tweak);
		BigInteger dec = FPE.decrypt(modulus, enc, key, tweak);

		Assert.assertTrue( dec.compareTo(plain) == 0 );
	}
	
	@Test
	public void testRanges() throws Exception
	{
		final byte[] key = "Here is my secret key!".getBytes();
	    final byte[] tweak = "tweak".getBytes();
	    
		for(int pow=2;pow<5;pow++)
		{
			int power = (int) Math.pow(10, pow);
			
			final int range = power;   // thus preserves the output range:  0 <= output < range
			final BigInteger modulus = BigInteger.valueOf(range);
			
			System.out.print("Testing 0 -> " + power);
			int count = 0;
			for(int i=0;i<power;i++){
				
				BigInteger plain = BigInteger.valueOf(i);
			    BigInteger enc = FPE.encrypt(modulus, plain, key, tweak);
			    BigInteger dec = FPE.decrypt(modulus, enc, key, tweak);

			    Assert.assertTrue( plain.compareTo(dec) == 0 );
			    
			    Assert.assertTrue(enc.compareTo(BigInteger.ZERO) >= 0);
			    Assert.assertTrue( enc.compareTo(modulus) < 0);
			    count++;
			}
			System.out.println(" OK (" + count + ")");<commit_msg>Add test for sample output<commit_after>package net._95point2.fpe;

import java.math.BigInteger;
import java.util.Random;

import org.junit.Assert;
import org.junit.Test;

import net._95point2.fpe.FPE;

public class FPETests 
{
	@Test
	public void testBasic() throws Exception
	{
		final byte[] key = "Here is my secret key!".getBytes();
	    final byte[] tweak = "tweak".getBytes();
	    final int range = 100;
		final BigInteger modulus = BigInteger.valueOf(range);
		
		BigInteger plain = BigInteger.valueOf(53);
		BigInteger enc = FPE.encrypt(modulus, plain, key, tweak);
		BigInteger dec = FPE.decrypt(modulus, enc, key, tweak);

		Assert.assertTrue( dec.compareTo(plain) == 0 );
	}
	
	@Test
	public void testRanges() throws Exception
	{
		final byte[] key = "Here is my secret key!".getBytes();
	    final byte[] tweak = "tweak".getBytes();
	    
		for(int pow=2;pow<5;pow++)
		{
			int power = (int) Math.pow(10, pow);
			
			final int range = power;   // thus preserves the output range:  0 <= output < range
			final BigInteger modulus = BigInteger.valueOf(range);
			
			System.out.print("Testing 0 -> " + power);
			int count = 0;
			for(int i=0;i<power;i++){
				
				BigInteger plain = BigInteger.valueOf(i);
			    BigInteger enc = FPE.encrypt(modulus, plain, key, tweak);
			    BigInteger dec = FPE.decrypt(modulus, enc, key, tweak);

			    Assert.assertTrue( plain.compareTo(dec) == 0 );
			    
			    Assert.assertTrue(enc.compareTo(BigInteger.ZERO) >= 0);
			    Assert.assertTrue( enc.compareTo(modulus) < 0);
			    count++;
			}
			System.out.println(" OK (" + count + ")");
			
		}
	}
	
	@Test
	public void testSampleRanges() throws Exception
	{
		final byte[] key = "Here is my secret key!".getBytes();
	    final byte[] tweak = "tweak".getBytes();
	    
	    Random rand = new Random();
	    
		for(int pow=2;pow<5;pow++)
		{
			int power = (int) Math.pow(10, pow);
			
			final int range = power;   // thus preserves the output range:  0 <= output < range
			final BigInteger modulus = BigInteger.valueOf(range);
			
			System.out.println("Testing modulus: 0 -> " + power);
			int count = 0;
			for(int i=0;i<5;i++){
				
				BigInteger plain = BigInteger.valueOf(rand.nextInt(range));
			    BigInteger enc = FPE.encrypt(modulus, plain, key, tweak);
			    BigInteger dec = FPE.decrypt(modulus, enc, key, tweak);

			    System.out.println("Plain: " + plain + " Encrypted: " + enc);
			    
			    Assert.assertTrue( plain.compareTo(dec) == 0 );
			    
			    Assert.assertTrue(enc.compareTo(BigInteger.ZERO) >= 0);
			    Assert.assertTrue( enc.compareTo(modulus) < 0);
			    count++;
			}
{'fraction_non_alphanumeric': 0.1417023300047551, 'fraction_numerical': 0.01378982406086543, 'mean_word_length': 3.12855740922473, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 9, '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': '7382757', 'n_tokens_mistral': 1624, 'n_tokens_neox': 1373, 'n_words': 356}