org.refcodes.security.ext.chaos.impls.ChaosKeyImpl Maven / Gradle / Ivy
// /////////////////////////////////////////////////////////////////////////////
// REFCODES.ORG
// /////////////////////////////////////////////////////////////////////////////
// This code is copyright (c) by Siegfried Steiner, Munich, Germany and licensed
// under the following (see "http://en.wikipedia.org/wiki/Multi-licensing")
// licenses:
// -----------------------------------------------------------------------------
// GNU General Public License, v3.0 ("http://www.gnu.org/licenses/gpl-3.0.html")
// -----------------------------------------------------------------------------
// Apache License, v2.0 ("http://www.apache.org/licenses/LICENSE-2.0")
// -----------------------------------------------------------------------------
// Please contact the copyright holding author(s) of the software artifacts in
// question for licensing issues not being covered by the above listed licenses,
// also regarding commercial licensing models or regarding the compatibility
// with other open source licenses.
// /////////////////////////////////////////////////////////////////////////////
package org.refcodes.security.ext.chaos.impls;
import javax.crypto.SecretKey;
import org.apache.commons.lang.ArrayUtils;
import org.refcodes.numerical.NumericalUtility;
import org.refcodes.security.alt.chaos.ChaosKey;
/**
* Thanks Christian Pontesegger for the very good example on
* "Writing your own JCA extensions - a full cipher" at:
* "http://codeandme.blogspot.de/2013/07/writing-your-own-jca-extensions-full.html"
* and for the very good example on
* "Writing your own JCA extensions - a simple digest " at:
* "http://codeandme.blogspot.de/2013/06/writing-your-own-jca-extensions-simple.html"
*/
public class ChaosKeyImpl implements ChaosKey, SecretKey {
// /////////////////////////////////////////////////////////////////////////
// STATICS:
// /////////////////////////////////////////////////////////////////////////
// /////////////////////////////////////////////////////////////////////////
// CONSTANTS:
// /////////////////////////////////////////////////////////////////////////
private static final long serialVersionUID = 1L;
// /////////////////////////////////////////////////////////////////////////
// VARIABLES:
// /////////////////////////////////////////////////////////////////////////
private double _x0;
private double _a;
private double _s;
// /////////////////////////////////////////////////////////////////////////
// CONSTRUCTORS:
// /////////////////////////////////////////////////////////////////////////
// /////////////////////////////////////////////////////////////////////////
// INJECTION:
// /////////////////////////////////////////////////////////////////////////
// /////////////////////////////////////////////////////////////////////////
// METHODS:
// /////////////////////////////////////////////////////////////////////////
public ChaosKeyImpl( double x0, double a, double s ) {
if ( x0 < 0 || x0 > 1 ) throw new IllegalArgumentException( "The value x(0) was <" + x0 + ">, though must be between <0> and <1> (0 <= x0 <= 1)" );
if ( a < 3.57 || a > 4 ) throw new IllegalArgumentException( "The value A was <" + a + ">, though must be between <3.57> and <4> (3.57 <= A <= 4)" );
if ( s > Long.MAX_VALUE ) throw new IllegalArgumentException( "The value S was <" + s + ">, though must be at most <" + Long.MAX_VALUE + "> (S <= Long.MAX_VALUE)" );
_x0 = x0;
_a = a;
_s = s;
}
@Override
public String getAlgorithm() {
return ChaosProviderImpl.PROVIDER_NAME;
}
@Override
public String getFormat() {
return getAlgorithm() + " format";
}
@Override
public byte[] getEncoded() {
byte[] theXs = NumericalUtility.toBytes( _x0 );
byte[] theAs = NumericalUtility.toBytes( _a );
byte[] theSs = NumericalUtility.toBytes( _s );
byte[] theTmps = ArrayUtils.addAll( theXs, theAs );
return ArrayUtils.addAll( theTmps, theSs );
}
@Override
public double getX0() {
return _x0;
}
@Override
public double getA() {
return _a;
}
@Override
public double getS() {
return _s;
}
// /////////////////////////////////////////////////////////////////////////
// HOOKS:
// /////////////////////////////////////////////////////////////////////////
// /////////////////////////////////////////////////////////////////////////
// HELPER:
// /////////////////////////////////////////////////////////////////////////
// /////////////////////////////////////////////////////////////////////////
// INNER CLASSES:
// /////////////////////////////////////////////////////////////////////////
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy