Re: Beginner's Algorithm
From: Michael Amling (nospam_at_nospam.com)
Date: 10/01/03
- Next message: Bartosz Zoltak: "Re: NIST randomness-tests - EXE?"
- Previous message: Bartosz Zoltak: "Re: VMPC Stream Cipher - ideas on potential weaknesses?"
- In reply to: Crown&7: "Beginner's Algorithm"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Date: Wed, 01 Oct 2003 13:15:36 GMT
Crown&7 wrote:
> For fun I decided to whip up an encryption algorithm using Java. I know
> nothing about cryptogrophy and I'm sure it shows, so please go easy on me.
> I'm looking for feedback on the originality and strength of the algorithm
> (considering if it had a 'real' random number generator) and, if anyone has
> time, suggestions on how to improve it. The algorithm is restricted to
> outputting only plain text characters that's why I decided to use a
> character map technique so I could choose the valid input/output characters.
>
> The algorithm:
> Randomly generate two characters and place them at the front of the
> string to be encrypted
> Use a seed value to start a random number generator
> Do a typical character offset mapping using random numbers and character
> map,
> but with a little twist. Use the numeric values of previous two
> characters in the encrypted string
> to add to the random number used to do the mapping of the current
> character.
>
> Adding the previous two characters into the mapping algorithm definitely
> helped it generate a more random sequence of characters when given the same
> input, but does it really add to the strength?
If you want to encrypt in Java, implement any of the five AES finalists.
> Here is the code:
>
> import java.util.Random;
>
> public class myEncrypt
> {
>
> private static final String myCharMap = new String(
> "P>H2Fe8X@KlfZ&RiWkUmp%qrou.x,zCwnD)EGyacIL{" +
> "M6dvO_Qg?hSA;bT+V[jY134B5t7<0!#$^*(s-J}9]:N`~");
There's no point in constructing a "new String" of a String literal.
Just use the String literal itself.
[...]
>
> public static String encrypt (String charMap,
> String dataIn,
> long seed) throws Exception
> {
> StringBuffer result = new StringBuffer(dataIn.length()+2);
> StringBuffer data = new StringBuffer(dataIn.length()+2);
> Random rand = new Random(seed);
I haven't actually looked into its algorithm, but it's unlikely that
java.util.Random is cryptographically suited to your purpose.
> Random rand2 = new
> Random(Math.abs(System.currentTimeMillis()-seed));
> int offset = 0;
> int location;
> int lenMap;
>
>
> data.append(charMap.charAt((int)Math.floor((charMap.length()*rand2.nextDoubl
> e()))));
There's really no need to use floating point here. This would be
somewhat simpler and faster if you replaced
"(int)Math.floor(charMap.length()*rand2.nextDouble())" with
"uniform(rand2, charMap.length())", where uniform is
int uniform(Random rnd, int limit) {
int mini=Integer.MAX_VALUE%limit, candidate;
while ((candidate=rnd.nextInt() & Integer.MAX_VALUE)<=mini) {
}
return candidate%limit;
}
>
> data.append(charMap.charAt((int)Math.floor((charMap.length()*rand2.nextDoubl
> e()))));
> data.append(dataIn);
It would be simpler and faster if you used two char variables to hold
the two previous characters, eliminating the need for the StringBuffer
variable named "data".
[...]
--Mike Amling
- Next message: Bartosz Zoltak: "Re: NIST randomness-tests - EXE?"
- Previous message: Bartosz Zoltak: "Re: VMPC Stream Cipher - ideas on potential weaknesses?"
- In reply to: Crown&7: "Beginner's Algorithm"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Relevant Pages
|