Logo
Distributed Genetic Programming Framework
print print

File org.sfc.crypt.algorithms.MergeKey.java

Here you can find all the information about the file org.sfc.crypt.algorithms.MergeKey.java. You may explore it here or download it onto your local disk.
/*
 * Copyright (c) 2006 Thomas Weise
 * 
 * E-Mail           : tweise@gmx.de
 * Creation Date    : 2006-06-30 12:58:03
 * Original Filename: org.sfc.crypt.algorithms.MergeKey.java
 * Version          : 1.0.0
 * Last modification: 2006-06-30
 *                by: Thomas Weise
 * 
 * License          : GNU LESSER GENERAL PUBLIC LICENSE
 *                    Version 2.1, February 1999
 *                    You should have received a copy of this license along
 *                    with this library; if not, write to the Free Software
 *                    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *                    MA 02111-1307, USA or download the license under
 *                    http://www.gnu.org/copyleft/lesser.html.
 *                    
 * Warranty         : This software is provided "as is" without any
 *                    warranty; without even the implied warranty of
 *                    merchantability or fitness for a particular purpose.
 *                    See the Gnu Lesser General Public License for more
 *                    details.
 */

 
package org.sfc.crypt.algorithms;

import org.sfc.crypt.CryptographicAlgorithm;
import org.sfc.crypt.CryptographicKey;

/**
 * The merge key cryptographic algorithm merges the key and the plain text.
 *
 * @author Thomas Weise
 */

public final class MergeKey extends CryptographicAlgorithm
  {

/**
 * Create a new instance of the add-key algorithm.
 * @param p_next    The next algorithm to be executed after this one.
 * @param p_key     The cryptographic key to be used.
 */

  public MergeKey  (final CryptographicAlgorithm p_next,
                    final CryptographicKey       p_key)
    {
    super(p_next, p_key);
    }
  
/**
 * This method is called to encrypt a block of bytes (plain text).
 * @param p_data    The data bytes to be encrypted.
 * @param p_key     The key to be used for encryption.
 */

  @Override
  protected final     void  encrypt (final byte[]     p_data,
                                     final byte[]     p_key)
    {
    int l_i;
    
    for(l_i = (Math.max(p_data.length, p_key.length)<<3); l_i >= 0; l_i--)
      {
      switch(Math.abs(get_byte(p_key, l_i) % 5))
        {
        case 0:
          {
          set_long(p_data, l_i, get_long(p_data, l_i) + get_long(p_key, l_i));
          break;
          }
          
        case 1:
          {
          set_int(p_data, l_i, get_int(p_data, l_i) - get_int(p_key, l_i));
          break;
          }
          
        case 2:
          {
          set_short(p_data, l_i,
               (short)(get_short(p_data, l_i) - get_short(p_key, l_i)));
          break;
          }
          
        case 3:
          {
          set_byte(p_data, l_i,
               (byte)(get_byte(p_data, l_i) + get_byte(p_key, l_i)));
          break;
          }
          
        default:
          {
          if(get_bit(p_key, l_i)) toggle_bit(p_data, l_i);
          break;
          }        
        }      
      }
    }
  
/**
 * This method is called to decrypt a encrypted block of bytes (cipher
 * text).
 * @param p_data    The (encrypted) data bytes to be decrypted.
 * @param p_key     The key to be used for decryption.
 */

  @Override
  protected final     void  decrypt (final byte[]     p_data,
                                     final byte[]     p_key)
    {
    int l_i, l_j;
    
    l_j = (Math.max(p_data.length, p_key.length)<<3);
    for(l_i = 0; l_i <= l_j; l_i++)
      {
      
      switch(Math.abs(get_byte(p_key, l_i) % 5))
        {
        case 0:
          {
          set_long(p_data, l_i, get_long(p_data, l_i) - get_long(p_key, l_i));
          break;
          }
          
        case 1:
          {
          set_int(p_data, l_i, get_int(p_data, l_i) + get_int(p_key, l_i));
          break;
          }
          
        case 2:
          {
          set_short(p_data, l_i,
               (short)(get_short(p_data, l_i) + get_short(p_key, l_i)));
          break;
          }
          
        case 3:
          {
          set_byte(p_data, l_i,
               (byte)(get_byte(p_data, l_i) - get_byte(p_key, l_i)));
          break;
          }
          
        default:
          {
          if(get_bit(p_key, l_i)) toggle_bit(p_data, l_i);
          break;
          }        
        }
      }
    }
  
/**
 * Obtain a human readable name of this crypt algorithm.
 * @return A human readable name of this crypt algorithm.
 */

  @Override
  public    final String  toString()
    {
    return "merge key";
    }
  }

File Information:

file name:MergeKey.java
package:org.sfc.crypt.algorithms
qualified name:org.sfc.crypt.algorithms.MergeKey.java
file type:Java Source File
download location:download http://dgpf.sourceforge.net/source/org/sfc/crypt/algorithms/MergeKey.java
size:4.587 KB (4698 B)
uploaded: 2015-07-22 04:11:11 GMT+0000
last update: 2006-06-30 10:28:36 GMT+0000
last access: 2018-01-23 19:32:30 GMT+0000

statistics online since 2006-01-02.   RSS Feed
Contact us by sending an email to tweise@gmx.de to receive further information, to report errors, or to join our project.
All content on this site (http://dgpf.sourceforge.net/) is LGPL-licensed.
http://dgpf.sourceforge.net/scripts/source/source.php last modified at 2015-07-22 04:10:53 GMT+0000 served at 2018-01-23 19:32:30 GMT+0000.
Valid CSS Valid XHTML 1.1
Valid RSS SourceForge.net Logo