Hi, I've written a simple encryption algorithm today and would like to
ask if anyone can judge upon how secure it is?
Attached: crypt.java and cryptExample.java
/* crypt.java
*
* Secure encryption algorythm class. This class is based on
* the idea to lining up bytes of text with a long line of random
* numbers to ensure an encryption impossible to break without
* the seed.
*
* Version 0.1
* Author Lars Schöning
* Date 27/11/2005 ISO
*
* Note: The random generation algorhythm is inherited from
* the java.util.Random package and not yet customized (todo).
* Moreover the seed generation process has to be modified.
*
* Ps: I'm a n00b at professional encryption, so in case you find
* a way to break this algorythm (besides finding a hole in the
* String2seed generation or the limitation of 2^64 possibilities)
* please tell me about it (lars y-px com).
*
*
* www.y-px.com
*/
public class crypt
{
private long seed;
private long password;
public crypt()
{
this.seed = (10 ^ 0x5DEECE66DL) & ((1L << 48) - 1);
}
public crypt(long seed)
{
this.seed = (seed ^ 0x5DEECE66DL) & ((1L << 48) - 1);
}
public crypt(String password)
{
long number = 0;
// This will have to be modified to generate a more secure seed.
for(int i = 0; i < password.length(); i ++)
number += (i + 1) * password.charAt(i);
this.seed = (number ^ 0x5DEECE66DL) & ((1L << 48) - 1);;
}
public int random()
{
this.seed = (this.seed * 0x5DEECE66DL + 0xBL) & ((1L << 48) - 1);
return (int)(this.seed >>> 40);
}
public byte[] encrypt(byte[] text)
{
return encrypt(text,false);
}
public byte[] encrypt(byte[] text, boolean add)
{
if(!add)
this.seed = this.password;
for(int i = 0; i < text.length; i ++ )
text[i] = (byte) (text[i] + random());
return text;
}
public byte[] decrypt(byte[] text)
{
return decrypt(text,false);
}
public byte[] decrypt(byte[] text, boolean add)
{
if(!add)
this.seed = this.password;
for(int i = 0; i < text.length; i ++ )
text[i] = (byte) (text[i] - random());
return text;
}
}
public class cryptExample
{
static String password = "test";
static String text = "*TOP SECRET DUMMY TEXT*\r\nLorem Ipsum is simply
dummy text of the printing and typesetting industry. Lorem Ipsum has
been the industry's standard dummy text ever since the 1500s, when an
unknown printer took a galley of type and scrambled it to make a type
specimen book. It has survived not only five centuries, but also the
leap into electronic typesetting, remaining essentially unchanged. It
was popularised in the 1960s with the release of Letraset sheets
containing Lorem Ipsum passages, and more recently with desktop
publishing software like Aldus PageMaker including versions of Lorem
Ipsum.";
public static void main(String[] args)
{
crypt c = new crypt(password);
byte[] t = c.encrypt(text.getBytes());
System.out.println("\nEncrypted:");
toHex(t);
toString(t);
t = c.decrypt(t);
System.out.println("\nDecrypted:");
toHex(t);
toString(t);
}
public static void toHex(byte[] t)
{
int n;
for(int i = 0; i < t.length; i ++)
{
n = (0xff & t[i]);
String h = "" ;
int r=0;
int q=0;
int nn=n ;
do
{
r=nn % 16;
nn= nn / 16;
switch (r)
{
case 10: h = "A" + h; break;
case 11: h = "B" + h; break;
case 12: h = "C" + h; break;
case 13: h = "D" + h; break;
case 14: h = "E" + h; break;
case 15: h = "F" + h; break;
default: h = r + h; break;
}
} while (nn > 0);
if(h.length() == 1)
h = "0" + h;
System.out.print(h + " ");
if(i % 50 == 49)
System.out.print("\n");
}
}
public static void toString(byte[] t)
{
System.out.println("\n" + new String(t));
}
}
Received on Sat Dec 3 04:20:03 2005