This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-10-22 22:54:25

GeonoTRON2000
Scratcher
Registered: 2009-12-24
Posts: 1000+

C3F1 aka Centipede

C3F1 is a new hashing algorithm I'm writing in Java.  It divides the input into 16-byte segments and handles them individually.  The problem is, the last digit actually has no effect.  For example chromium555 and chromium556 would output the same.  I'm wondering how I might be able to fix this.
The Code:

Code:

package org.cfagency.c3f1;

public class C3F1 {
    
    // make last digit matter!!!

    public byte[] hash (byte[] source) {
        String baseNumString = "";
        String resultString = "";
        for (int index = 0; index < source.length; index++) {
            byte b = source[index];
            int i = Math.abs((int) b);
            baseNumString += Integer.toString(i);
        }
        int segments;
        if (baseNumString.length() % 16 > Math.ceil(Double.MIN_VALUE*16))
            segments = (int) Math.ceil(baseNumString.length()/16) + 1;
        else
            segments = (int) Math.ceil(baseNumString.length()/16);
        for (int segmentNumber = 1; segmentNumber <= segments; segmentNumber++) {
            long base;
            int segmentIndex = segmentNumber - 1;
            if (segmentNumber < segments) {
                String lstring;
                lstring = baseNumString.substring(segmentIndex, 16);
                if (lstring.length() == 0) {
                    lstring = "0";
                }
                base = new Long(lstring);
            }
            else {
                String lstring;
                lstring = baseNumString.substring(segmentIndex, baseNumString.length()-(segmentIndex)*16);
                if (lstring.length() == 0) {
                    lstring = "0";
                }
                base = new Long(lstring);
            }
            // top secret operations with the use variable
            resultString += Long.toString(use);
        }
        byte[] result = resultString.getBytes();
        return result;
    }
    
    public static byte[] hashBytes (byte[] source) {
        return new C3F1().hash(source);
    }

}

Last edited by GeonoTRON2000 (2012-10-22 22:55:30)


http://i.imgur.com/BAEgGDL.png

Offline

 

#2 2012-10-22 22:57:38

nXIII
Community Moderator
Registered: 2009-04-21
Posts: 1000+

Re: C3F1 aka Centipede

Why not use MessageDigest?

EDIT: 7

Last edited by nXIII (2012-10-22 22:59:07)


nXIII

Offline

 

#3 2012-10-22 22:59:06

GeonoTRON2000
Scratcher
Registered: 2009-12-24
Posts: 1000+

Re: C3F1 aka Centipede

nXIII wrote:

Why not use MessageDigest?

Because it's more fun to make your own.


http://i.imgur.com/BAEgGDL.png

Offline

 

#4 2012-10-22 22:59:32

nXIII
Community Moderator
Registered: 2009-04-21
Posts: 1000+

Re: C3F1 aka Centipede

GeonoTRON2000 wrote:

nXIII wrote:

Why not use MessageDigest?

Because it's more fun to make your own.

However, it's far less effective.


nXIII

Offline

 

#5 2012-10-22 23:04:38

GeonoTRON2000
Scratcher
Registered: 2009-12-24
Posts: 1000+

Re: C3F1 aka Centipede

nXIII wrote:

GeonoTRON2000 wrote:

nXIII wrote:

Why not use MessageDigest?

Because it's more fun to make your own.

However, it's far less effective.

I'm not shooting for effective.  I'm shooting for "It works!".  It's much more exciting that way.


http://i.imgur.com/BAEgGDL.png

Offline

 

#6 2012-10-24 17:59:06

DigiTechs
Scratcher
Registered: 2011-04-30
Posts: 500+

Re: C3F1 aka Centipede

I found this error with my for block for BYOB, the way I fixed it was by adding 1 onto the length of the list. I belive if you add one onto the variable of characters to hash, it should work properly. But, I haven't read your code and as I do not know Java, I do not know if you have stored a variable for the characters to hash.


I'm back.
Maybe.

Offline

 

Board footer