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:
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)
Offline
Why not use MessageDigest?
EDIT: 7
Last edited by nXIII (2012-10-22 22:59:07)
Offline
nXIII wrote:
Why not use MessageDigest?
Because it's more fun to make your own.
Offline
However, it's far less effective.
Offline
nXIII wrote:
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.
Offline
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.
Offline