Giter Site home page Giter Site logo

javafpe's Introduction

FPE for Java

Format Preserving Encryption

So, the real credit is due to all authors in the chain!

Usage

import java.math.BigInteger;

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 = 1000;
		final BigInteger modulus = BigInteger.valueOf(range);
		
		BigInteger plain = BigInteger.valueOf(345);
		BigInteger enc = FPE.encrypt(modulus, plain, key, tweak);
		BigInteger dec = FPE.decrypt(modulus, enc, key, tweak);

		Assert.assertTrue( dec.compareTo(plain) == 0 );
	}
}

Modulus

The modulus prescribes the range of numbers and is always powers of ten. If the input range is 0 <= range <= 999 then then modulus must be set to 1000

Example Output

Testing modulus: 0 -> 100
Plain: 35 Encrypted: 83
Plain: 35 Encrypted: 83
Plain: 7 Encrypted: 27
Plain: 53 Encrypted: 0
Plain: 32 Encrypted: 96

Testing modulus: 0 -> 1000
Plain: 520 Encrypted: 636
Plain: 754 Encrypted: 359
Plain: 580 Encrypted: 152
Plain: 855 Encrypted: 12
Plain: 926 Encrypted: 190

Testing modulus: 0 -> 10000
Plain: 2868 Encrypted: 10
Plain: 5210 Encrypted: 3455
Plain: 9410 Encrypted: 4502
Plain: 4864 Encrypted: 1730
Plain: 4974 Encrypted: 3599

Further Notes

  • When using a modulus of 100 and numbers in the range 0 <= range <= 99, there will usually be a collision where input==output.

javafpe's People

Contributors

robshep avatar msiedlarek avatar

Watchers

James Cloos avatar Houping Zhu avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.