what you don't know can hurt you
Home Files News &[SERVICES_TAB]About Contact Add New

XorCryptographer.java

XorCryptographer.java
Posted Dec 21, 1999

XorCryptographer.java

tags | java, encryption
SHA-256 | 869683fad1dee072ce6d9f319e0f9c8ac5d81315eb224c81b79ad286ec683adc

XorCryptographer.java

Change Mirror Download
//
// XorCryptographer.java - A fast (and unsafe) cryptographer that uses a simple xor algorithm.
//
// Copyright (C) 1996-1997 by Connect Software, Inc. All rights reserved.
//
// All the usual legal disclaimers and restrictions applicable to cryptography apply.
//
// Disclaimer: This is nothing more than toy cryptography (similar to the one used in digital cellular phones).
//
// Designed and written by Gionata Mettifogo.
//

package connect.cryptography; // belong to the cryptography package

public class XorCryptographer extends Cryptographer
{
/** Initialize xor cryptographer using given string as the encryption and decryption private key. */

public XorCryptographer(String privateKey)
{
int len = privateKey.length(); // length of the private key string

key = new byte[len]; // create array of bytes for the key

privateKey.getBytes(0,len,key,0); // convert string into array of bytes
}

/** Initialize xor cryptographer using standard private key. */

public XorCryptographer()
{
this("R1@t5&*43,.:{=zDy)_y+}]|y&7k5/#3gt,{szq!`:+"); // use default key
}

/** Encrypts the given block of data. */

public void encrypt(byte [] data, int offset, int length)
{
for(int i = offset, j = offset + length ; i < j ; i++) // encrypt each byte in the data
{
byte b = data[i];

data[i] ^= key[count++ % key.length] ^ previous; // xor current byte with key and previous byte

previous = b; // remember current uncrypted byte (will be used to encrypt the next)
}
}

/** Decrypts the given block of data. */

public void decrypt(byte [] data, int offset, int length)
{
for(int i = offset, j = offset + length ; i < j ; i++) // encrypt each byte in the data
{
data[i] ^= previous ^ key[count++ % key.length]; // xor current byte with key and previous byte

previous = data[i]; // remember current byte (will be used to encrypt the next)
}
}

/** The key used for encryption. */

private byte [] key = null;

/** Index in key of the byte that will be used to encrypt the next byte. */

private int count = 0;

/** The last byte encrypted (used to encrypt following byte). */

private byte previous = (byte) 0xE3; // this is just some random number (so that the first byte also looks like it's encrypted)
}

Login or Register to add favorites

File Archive:

November 2024

  • Su
  • Mo
  • Tu
  • We
  • Th
  • Fr
  • Sa
  • 1
    Nov 1st
    30 Files
  • 2
    Nov 2nd
    0 Files
  • 3
    Nov 3rd
    0 Files
  • 4
    Nov 4th
    12 Files
  • 5
    Nov 5th
    44 Files
  • 6
    Nov 6th
    18 Files
  • 7
    Nov 7th
    9 Files
  • 8
    Nov 8th
    8 Files
  • 9
    Nov 9th
    3 Files
  • 10
    Nov 10th
    0 Files
  • 11
    Nov 11th
    14 Files
  • 12
    Nov 12th
    20 Files
  • 13
    Nov 13th
    63 Files
  • 14
    Nov 14th
    18 Files
  • 15
    Nov 15th
    8 Files
  • 16
    Nov 16th
    0 Files
  • 17
    Nov 17th
    0 Files
  • 18
    Nov 18th
    18 Files
  • 19
    Nov 19th
    7 Files
  • 20
    Nov 20th
    13 Files
  • 21
    Nov 21st
    6 Files
  • 22
    Nov 22nd
    48 Files
  • 23
    Nov 23rd
    0 Files
  • 24
    Nov 24th
    0 Files
  • 25
    Nov 25th
    60 Files
  • 26
    Nov 26th
    0 Files
  • 27
    Nov 27th
    44 Files
  • 28
    Nov 28th
    0 Files
  • 29
    Nov 29th
    0 Files
  • 30
    Nov 30th
    0 Files

Top Authors In Last 30 Days

File Tags

Systems

packet storm

© 2024 Packet Storm. All rights reserved.

Services
Security Services
Hosting By
Rokasec
close