|
||||||
| Games Kick back, relax, and have some fun! |
| View Poll Results: Vote on the Algorithm below | |||
| #1 in C# |
|
2 | 10.00% |
| #2 in Java |
|
2 | 10.00% |
| #3 in C++ |
|
7 | 35.00% |
| #4 in VB |
|
9 | 45.00% |
| Voters: 20. You may not vote on this poll | |||
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||||
|
Pasted below is the four Hash Algorithms that I received. I will paste the algorithms in the order that I received it and a link to the source file and/or project files.
Look through each code snippet and vote for your favorite algorithm. I urge you to compile each one and check for errors. Read the rules at the bottom before posting or voting! #1 - Using C# Download all project files and binary for #1 here. Code:
/*
* CodeCall
* hash algorithm contest
*
* a hash algorithm that takes a string as input and produces a 20 numbers
* that uniquely identify this value with some collision resistance (i hope so :) )
*
* 4/10/2008
*
* */
using System;
using System.Windows.Forms;
namespace hash_value
{
public partial class Form1 : Form
{
private string gethash(string input_str)
{
//converting the string input value to a char array to manipulate it
char[] input = input_str.ToCharArray();
//a bool variable used as a collision resistance
//by changing the value of the hash depending on the order of the chars in the string value
bool x = true;
//the hash array is the array that holds the results of the hashing process
Int64[] hash = new Int64[2];
//the int that will hold the main sum of the int values
int num = 0;
//loop that exits when reaches the length of the input array
for (int i = 0; i < input.Length; i++)
{
//using two diffrent equations as a collision resistance. to avoid making the same output from "example" and "exampel"
if (x)
{
//storing the int value resulting from the 'Convert.ToChar(char[])' method in the num
num += Convert.ToChar(input[i]);
//changing the value of the bool x, and moving to the next char in the array using a continue statement
x = false;
continue;
}
if (!x)
{
num += Convert.ToChar(input[i]) * Convert.ToChar(input [i]);
x = true;
}
}
//storing the values and preparing them for the final result
hash[0] = input.Length;
hash[1] = num;
string outputhash = hash[0].ToString() + hash[1].ToString();
//setting the result length '20'
while (outputhash.Length != 20)
{
if (outputhash.Length < 20)
{
hash[1] = Convert.ToInt64(hash[1] * 1.5);
}
else if (outputhash.Length > 20)
{
hash[1] = Convert.ToInt64(hash[1] / 1.5);
}
//for some wierd reason -i dont know why- sometimes negative numbers is produced, to eleminate negative number i used this code
if (hash[1] < 0)
{
hash[1] *= - 1;
}
//updating the result string
outputhash = hash[0].ToString() + hash[1].ToString();
}
return outputhash;
}
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (tbinput.Text != "")
{
tboutput.Text = gethash(tbinput.Text);
tlength.Text = tboutput.Text.Length.ToString();
}
}
private void button2_Click(object sender, EventArgs e)
{
this.tbinput.Text = "";
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
Download source file here. Download JAR file here. Code:
package main;
import java.io.IOException;
public class starter {
public String Recrypt(String stringin, MD5 m) throws IOException{
String hash = "";
//take the first md5 hash of the string input, save to stra
String stra = m.encrypt(stringin);
/**
* This while loop takes each 32 bit md5 hash and saves only
* 1 character from the hash each time it runs. It then outputs
* a brand new hash that is completely different from the first
*/
int k = 0;
while (k < 2000){
for (int i=0; i<32; i++){
String strb = m.encrypt(stra);
hash += strb.charAt(i);
}
stra = hash;
k++;
hash = "";
}
hash = stra; //makes hash a brand new encrypted md5 of the md5
/**
* Finally, we reverse the final hash and take only
* the first 20 bytes of it to fit the contest rules.
*/
String finalH = "";
for (int i=20; i>0; i--){
char c = stra.charAt(i);
finalH += c;
}
/**
* Lets return the final Hash
*/
return finalH;
}
public static void main(String[] args) throws IOException {
starter s = new starter();
MD5 m = new MD5();
/**
* Input your string to hash here
*/
String strin = args[0];
for (int i=1; i<args.length; i++)
{
strin += args[i]+" ";
}
//This prints out the new hash
System.out.println(s.Recrypt(strin, m));
}
}
//Since I didn't feel using a built in MD5 function was fair
//I went and found an actual implementation of it that worked.
//Credit to this code is below, it was found at:
//http://www.freevbcode.com/ShowCode.Asp?ID=741
//Do not ask me questions on the following code
//I will be unlikely able to respond with an intellegent answer!
/******************************************************************************
* Copyright (C) 2000 by Robert Hubley. *
* All rights reserved. *
* *
* This software is provided ``AS IS'' and any express or implied *
* warranties, including, but not limited to, the implied warranties of *
* merchantability and fitness for a particular purpose, are disclaimed. *
* In no event shall the authors be liable for any direct, indirect, *
* incidental, special, exemplary, or consequential damages (including, but *
* not limited to, procurement of substitute goods or services; loss of use, *
* data, or profits; or business interruption) however caused and on any *
* theory of liability, whether in contract, strict liability, or tort *
* (including negligence or otherwise) arising in any way out of the use of *
* this software, even if advised of the possibility of such damage. *
* *
******************************************************************************
*
* CLASS: MD5
*
* DESCRIPTION:
* This is a class which encapsulates a set of MD5 Message Digest functions.
* MD5 algorithm produces a 128 bit digital fingerprint (signature) from an
* dataset of arbitrary length. For details see RFC 1321 (summarized below).
* This implementation is derived from the RSA Data Security, Inc. MD5 Message-Digest
* algorithm reference implementation (originally written in C)
*
* AUTHOR:
* Robert M. Hubley 1/2000
*
*
* NOTES:
* Network Working Group R. Rivest
* Request for Comments: 1321 MIT Laboratory for Computer Science
* and RSA Data Security, Inc.
* April 1992
*
*
* The MD5 Message-Digest Algorithm
*
* Summary
*
* This document describes the MD5 message-digest algorithm. The
* algorithm takes as input a message of arbitrary length and produces
* as output a 128-bit "fingerprint" or "message digest" of the input.
* It is conjectured that it is computationally infeasible to produce
* two messages having the same message digest, or to produce any
* message having a given prespecified target message digest. The MD5
* algorithm is intended for digital signature applications, where a
* large file must be "compressed" in a secure manner before being
* encrypted with a private (secret) key under a public-key cryptosystem
* such as RSA.
*
* The MD5 algorithm is designed to be quite fast on 32-bit machines. In
* addition, the MD5 algorithm does not require any large substitution
* tables; the algorithm can be coded quite compactly.
*
* The MD5 algorithm is an extension of the MD4 message-digest algorithm
* 1,2]. MD5 is slightly slower than MD4, but is more "conservative" in
* design. MD5 was designed because it was felt that MD4 was perhaps
* being adopted for use more quickly than justified by the existing
* critical review; because MD4 was designed to be exceptionally fast,
* it is "at the edge" in terms of risking successful cryptanalytic
* attack. MD5 backs off a bit, giving up a little in speed for a much
* greater likelihood of ultimate security. It incorporates some
* suggestions made by various reviewers, and contains additional
* optimizations. The MD5 algorithm is being placed in the public domain
* for review and possible adoption as a standard.
*
* RFC Author:
* Ronald L.Rivest
* Massachusetts Institute of Technology
* Laboratory for Computer Science
* NE43 -324545 Technology Square
* Cambridge, MA 02139-1986
* Phone: (617) 253-5880
* EMail: Rivest@ theory.lcs.mit.edu
*
*
*
* CHANGE HISTORY:
*
* 0.1.0 RMH 1999/12/29 Original version
*
*/
//
//MD5 Class
//
class MD5
{
private static long S11 = 7L;
private static long S12 = 12L;
private static long S13 = 17L;
private static long S14 = 22L;
private static long S21 = 5L;
private static long S22 = 9L;
private static long S23 = 14L;
private static long S24 = 20L;
private static long S31 = 4L;
private static long S32 = 11L;
private static long S33 = 16L;
private static long S34 = 23L;
private static long S41 = 6L;
private static long S42 = 10L;
private static long S43 = 15L;
private static long S44 = 21L;
private static char pad[] = {128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0};
private char bytBuffer[] = new char[64];
private long lngState[] = new long[4];
private long lngByteCount = 0;
//
// Constructor
//
MD5()
{
this.init();
}
//
// Static Methods
//
private static long[] decode(char bytBlock[])
{
long lngBlock[] = new long[16];
int j = 0;
for(int i = 0; i < bytBlock.length; i += 4)
{
lngBlock[j++] = bytBlock[i] +
bytBlock[i+1] * 256L +
bytBlock[i+2] * 65536L +
bytBlock[i+3] * 16777216L;
}
return(lngBlock);
}
private static void transform(long lngState[], char bytBlock[])
{
long lngA = lngState[0];
long lngB = lngState[1];
long lngC = lngState[2];
long lngD = lngState[3];
long x[] = new long[16];
x = decode (bytBlock);
/* Round 1 */
lngA = ff (lngA, lngB, lngC, lngD, x[ 0], S11, 0xd76aa478L); /* 1 */
lngD = ff (lngD, lngA, lngB, lngC, x[ 1], S12, 0xe8c7b756L); /* 2 */
lngC = ff (lngC, lngD, lngA, lngB, x[ 2], S13, 0x242070dbL); /* 3 */
lngB = ff (lngB, lngC, lngD, lngA, x[ 3], S14, 0xc1bdceeeL); /* 4 */
lngA = ff (lngA, lngB, lngC, lngD, x[ 4], S11, 0xf57c0fafL); /* 5 */
lngD = ff (lngD, lngA, lngB, lngC, x[ 5], S12, 0x4787c62aL); /* 6 */
lngC = ff (lngC, lngD, lngA, lngB, x[ 6], S13, 0xa8304613L); /* 7 */
lngB = ff (lngB, lngC, lngD, lngA, x[ 7], S14, 0xfd469501L); /* 8 */
lngA = ff (lngA, lngB, lngC, lngD, x[ 8], S11, 0x698098d8L); /* 9 */
lngD = ff (lngD, lngA, lngB, lngC, x[ 9], S12, 0x8b44f7afL); /* 10 */
lngC = ff (lngC, lngD, lngA, lngB, x[10], S13, 0xffff5bb1L); /* 11 */
lngB = ff (lngB, lngC, lngD, lngA, x[11], S14, 0x895cd7beL); /* 12 */
lngA = ff (lngA, lngB, lngC, lngD, x[12], S11, 0x6b901122L); /* 13 */
lngD = ff (lngD, lngA, lngB, lngC, x[13], S12, 0xfd987193L); /* 14 */
lngC = ff (lngC, lngD, lngA, lngB, x[14], S13, 0xa679438eL); /* 15 */
lngB = ff (lngB, lngC, lngD, lngA, x[15], S14, 0x49b40821L); /* 16 */
/* Round 2 */
lngA = gg (lngA, lngB, lngC, lngD, x[ 1], S21, 0xf61e2562L); /* 17 */
lngD = gg (lngD, lngA, lngB, lngC, x[ 6], S22, 0xc040b340L); /* 18 */
lngC = gg (lngC, lngD, lngA, lngB, x[11], S23, 0x265e5a51L); /* 19 */
lngB = gg (lngB, lngC, lngD, lngA, x[ 0], S24, 0xe9b6c7aaL); /* 20 */
lngA = gg (lngA, lngB, lngC, lngD, x[ 5], S21, 0xd62f105dL); /* 21 */
lngD = gg (lngD, lngA, lngB, lngC, x[10], S22, 0x2441453L); /* 22 */
lngC = gg (lngC, lngD, lngA, lngB, x[15], S23, 0xd8a1e681L); /* 23 */
lngB = gg (lngB, lngC, lngD, lngA, x[ 4], S24, 0xe7d3fbc8L); /* 24 */
lngA = gg (lngA, lngB, lngC, lngD, x[ 9], S21, 0x21e1cde6L); /* 25 */
lngD = gg (lngD, lngA, lngB, lngC, x[14], S22, 0xc33707d6L); /* 26 */
lngC = gg (lngC, lngD, lngA, lngB, x[ 3], S23, 0xf4d50d87L); /* 27 */
lngB = gg (lngB, lngC, lngD, lngA, x[ 8], S24, 0x455a14edL); /* 28 */
lngA = gg (lngA, lngB, lngC, lngD, x[13], S21, 0xa9e3e905L); /* 29 */
lngD = gg (lngD, lngA, lngB, lngC, x[ 2], S22, 0xfcefa3f8L); /* 30 */
lngC = gg (lngC, lngD, lngA, lngB, x[ 7], S23, 0x676f02d9L); /* 31 */
lngB = gg (lngB, lngC, lngD, lngA, x[12], S24, 0x8d2a4c8aL); /* 32 */
/* Round 3 */
lngA = hh (lngA, lngB, lngC, lngD, x[ 5], S31, 0xfffa3942L); /* 33 */
lngD = hh (lngD, lngA, lngB, lngC, x[ 8], S32, 0x8771f681L); /* 34 */
lngC = hh (lngC, lngD, lngA, lngB, x[11], S33, 0x6d9d6122L); /* 35 */
lngB = hh (lngB, lngC, lngD, lngA, x[14], S34, 0xfde5380cL); /* 36 */
lngA = hh (lngA, lngB, lngC, lngD, x[ 1], S31, 0xa4beea44L); /* 37 */
lngD = hh (lngD, lngA, lngB, lngC, x[ 4], S32, 0x4bdecfa9L); /* 38 */
lngC = hh (lngC, lngD, lngA, lngB, x[ 7], S33, 0xf6bb4b60L); /* 39 */
lngB = hh (lngB, lngC, lngD, lngA, x[10], S34, 0xbebfbc70L); /* 40 */
lngA = hh (lngA, lngB, lngC, lngD, x[13], S31, 0x289b7ec6L); /* 41 */
lngD = hh (lngD, lngA, lngB, lngC, x[ 0], S32, 0xeaa127faL); /* 42 */
lngC = hh (lngC, lngD, lngA, lngB, x[ 3], S33, 0xd4ef3085L); /* 43 */
lngB = hh (lngB, lngC, lngD, lngA, x[ 6], S34, 0x4881d05L); /* 44 */
lngA = hh (lngA, lngB, lngC, lngD, x[ 9], S31, 0xd9d4d039L); /* 45 */
lngD = hh (lngD, lngA, lngB, lngC, x[12], S32, 0xe6db99e5L); /* 46 */
lngC = hh (lngC, lngD, lngA, lngB, x[15], S33, 0x1fa27cf8L); /* 47 */
lngB = hh (lngB, lngC, lngD, lngA, x[ 2], S34, 0xc4ac5665L); /* 48 */
/* Round 4 */
lngA = ii (lngA, lngB, lngC, lngD, x[ 0], S41, 0xf4292244L); /* 49 */
lngD = ii (lngD, lngA, lngB, lngC, x[ 7], S42, 0x432aff97L); /* 50 */
lngC = ii (lngC, lngD, lngA, lngB, x[14], S43, 0xab9423a7L); /* 51 */
lngB = ii (lngB, lngC, lngD, lngA, x[ 5], S44, 0xfc93a039L); /* 52 */
lngA = ii (lngA, lngB, lngC, lngD, x[12], S41, 0x655b59c3L); /* 53 */
lngD = ii (lngD, lngA, lngB, lngC, x[ 3], S42, 0x8f0ccc92L); /* 54 */
lngC = ii (lngC, lngD, lngA, lngB, x[10], S43, 0xffeff47dL); /* 55 */
lngB = ii (lngB, lngC, lngD, lngA, x[ 1], S44, 0x85845dd1L); /* 56 */
lngA = ii (lngA, lngB, lngC, lngD, x[ 8], S41, 0x6fa87e4fL); /* 57 */
lngD = ii (lngD, lngA, lngB, lngC, x[15], S42, 0xfe2ce6e0L); /* 58 */
lngC = ii (lngC, lngD, lngA, lngB, x[ 6], S43, 0xa3014314L); /* 59 */
lngB = ii (lngB, lngC, lngD, lngA, x[13], S44, 0x4e0811a1L); /* 60 */
lngA = ii (lngA, lngB, lngC, lngD, x[ 4], S41, 0xf7537e82L); /* 61 */
lngD = ii (lngD, lngA, lngB, lngC, x[11], S42, 0xbd3af235L); /* 62 */
lngC = ii (lngC, lngD, lngA, lngB, x[ 2], S43, 0x2ad7d2bbL); /* 63 */
lngB = ii (lngB, lngC, lngD, lngA, x[ 9], S44, 0xeb86d391L); /* 64 */
lngState[0] = (lngState[0] + lngA) & 0xFFFFFFFFL;
lngState[1] = (lngState[1] + lngB) & 0xFFFFFFFFL;
lngState[2] = (lngState[2] + lngC) & 0xFFFFFFFFL;
lngState[3] = (lngState[3] + lngD) & 0xFFFFFFFFL;
/* clear senstive information */
x = decode (pad);
}
private static long ff(long lngA,
long lngB,
long lngC,
long lngD,
long lngX,
long lngS,
long lngAC)
{
lngA = (lngA + (lngB & lngC | (~lngB) & lngD) + lngX + lngAC) & 0xFFFFFFFFL;
lngA = ((lngA << lngS) | (lngA >>> (32L-lngS))) & 0xFFFFFFFFL;
lngA = (lngA + lngB) & 0xFFFFFFFFL;
return(lngA);
}
private static long gg(long lngA,
long lngB,
long lngC,
long lngD,
long lngX,
long lngS,
long lngAC)
{
lngA = (lngA + (lngB & lngD | lngC & ~lngD) + lngX + lngAC) & 0xFFFFFFFFL;
lngA = ((lngA << lngS) | (lngA >>> (32L-lngS))) & 0xFFFFFFFFL;
lngA = (lngA + lngB) & 0xFFFFFFFFL;
return(lngA);
}
private static long hh(long lngA,
long lngB,
long lngC,
long lngD,
long lngX,
long lngS,
long lngAC)
{
lngA = (lngA + (lngB ^ lngC ^ lngD) + lngX + lngAC) & 0xFFFFFFFFL;
lngA = ((lngA << lngS) | (lngA >>> (32L-lngS))) & 0xFFFFFFFFL;
lngA = (lngA + lngB) & 0xFFFFFFFFL;
return(lngA);
}
private static long ii(long lngA,
long lngB,
long lngC,
long lngD,
long lngX,
long lngS,
long lngAC)
{
lngA = (lngA + (lngC ^ (lngB | ~lngD)) + lngX + lngAC) & 0xFFFFFFFFL;
lngA = ((lngA << lngS) | (lngA >>> (32L-lngS))) & 0xFFFFFFFFL;
lngA = (lngA + lngB) & 0xFFFFFFFFL;
return(lngA);
}
private void update(char bytInput[], long lngLen)
{
int index = (int)( this.lngByteCount % 64);
int i = 0;
this.lngByteCount += lngLen;
int partLen = 64 - index;
if (lngLen >= partLen)
{
for (int j = 0; j < partLen; ++j)
{
this.bytBuffer[j + index] = bytInput[j];
}
transform (this.lngState, this.bytBuffer);
for (i = partLen; i + 63 < lngLen; i += 64)
{
for (int j = 0; j<64; ++j)
{
this.bytBuffer[j] = bytInput[j+i];
}
transform (this.lngState, this.bytBuffer);
}
index = 0;
}
else
{
i = 0;
}
for (int j = 0; j < lngLen - i; ++j)
{
this.bytBuffer[index + j] = bytInput[i + j];
}
}
public void md5final()
{
char bytBits[] = new char[8];
int index, padLen;
long bits = this.lngByteCount * 8;
bytBits[0] = (char) (bits & 0xffL);
bytBits[1] = (char) ((bits >>> 8) & 0xffL);
bytBits[2] = (char) ((bits >>> 16) & 0xffL);
bytBits[3] = (char)((bits >>> 24) & 0xffL);
bytBits[4] = (char)((bits >>> 32) & 0xffL);
bytBits[5] = (char)((bits >>> 40) & 0xffL);
bytBits[6] = (char)((bits >>> 48) & 0xffL);
bytBits[7] = (char)((bits >>> 56) & 0xffL);
index = (int) this.lngByteCount%64;
if (index < 56 )
{
padLen = 56 - index;
}
else
{
padLen = 120 - index;
}
update(pad, padLen);
update(bytBits, 8);
}
private StringBuffer toHexString()
{
long myByte = 0;
StringBuffer mystring = new StringBuffer();
for (int j = 0; j < 4; ++j)
{
for (int i = 0; i < 32; i += 8)
{
myByte = (this.lngState[j] >>> i) & 0xFFL;
if (myByte < 16)
{
mystring.append("0" + Long.toHexString(myByte));
}
else
{
mystring.append(Long.toHexString(myByte));
}
}
}
return(mystring);
}
public void init()
{
this.lngByteCount = 0;
this.lngState[0] = 0x67452301L;
this.lngState[1] = 0xefcdab89L;
this.lngState[2] = 0x98badcfeL;
this.lngState[3] = 0x10325476L;
}
//
// MAIN routine, Modified by Phil to remove testing
//
public String encrypt (String str)
throws IOException
{
char chrTestData[] = new char[64];
MD5 md5Test = new MD5();
md5Test.init();
chrTestData = str.toCharArray();
md5Test.update(chrTestData,chrTestData.length);
md5Test.md5final();
return md5Test.toHexString().toString();
}
}
Download source code here. Code:
/*
g++ weakMD5.cpp -o weakMD5.exe
This is a modification of the MD5 algorithm as described on
http://en.wikipedia.org/wiki/MD5
for the contest located at
http://forum.codecall.net/games/10655-coder-battle-1-hash-algorithm.html
The modifications that have been made are processing 20 bit instead of 32 bit
chunks of data in order to meet the requirements of the contest.
This is copyrighted by ********** and is free to use/modify by anyone for
any purpose, just leave the attribution to me. Feel free to PM me if you have
any questions.
*/
#include <iostream>
#include <fstream>
#include <cmath>
using std::cout;
using std::pow;
using std::sin;
void output(unsigned long result){
switch (result){
case 0xf:cout<<"f";break;
case 0xe:cout<<"e";break;
case 0xd:cout<<"d";break;
case 0xc:cout<<"c";break;
case 0xb:cout<<"b";break;
case 0xa:cout<<"a";break;
default:cout<<result;
}
}
void process(unsigned long * h,unsigned char * k,unsigned long * w,unsigned char * r){
unsigned long a,b,c,d,f,g,swap;
int i;
const unsigned long mask=0xfffff;
a=h[0];
b=h[1];
c=h[2];
d=h[3];
for(i=0;i<64;i++){
if (i<16){
f=((b&c)|((!d)&c))&mask;
g=i;
}else if (i<32){
f=((d&b)|((!d)&c))&mask;
g=(5*i+1)%16;
}else if (i<48){
f=(b^c^d)&mask;
g=(3*i+5)%16;
}else{
f=(c^(b|(!d)))&mask;
g=(7*i)%16;
}
swap=d;
d=c;
c=b;
b=b + ((a+f+k[i]+w[i] << r[i])&mask) + ((a+f+k[i]+w[i] >> (20 - r[i]))&mask);
a=swap;
}
h[0] =(h[0] + a)&mask;
h[1] =(h[1] + b)&mask;
h[2] =(h[2] + c)&mask;
h[3] =(h[3] + d)&mask;
}
void pushw(unsigned long * w,unsigned char * temp){
int i;
for (i=0;i<64;i+=2){
w[i] = temp[5*i]*0x1000 + temp[5*i+1]*0x10 + temp[5*i+2]/0x10;
w[i+1] = (temp[5*i+2] % 0x10) * 0x10000 + temp[5*i+3]*0x100 + temp[5*i+4];
}
}
int main(int argc, char* argv[])
{
if (argc == 1){
cout<<"Usage: weakMD5 [filepath\\][filename]\n";
exit(1);
}
std::ifstream from(argv[1]);
if (!from){
cout<<"Error opening file "<<argv[1]<<"\n";
exit(2);
}
char ch;
//r is modified due to the reduced bit field region to shift in, basic structure is preserved
unsigned char r[64] = {4,9,14,18,4,9,14,18,4,9,14,18,4,9,14,18,2,6,11,16,2,6,11,16,2,6,11,16,2,6,11,16,1,8,13,19,1,8,13,19,1,8,13,19,1,8,13,19,3,7,12,17,3,7,12,17,3,7,12,17,3,7,12,17};
unsigned char k[64];
for(int i=0;i<64;i++){
k[i] = floor(abs(sin(i+1)*256));
}
unsigned long h[4];
h[0]=0x01234;
h[1]=0x56789;
h[2]=0xABCDE;
h[3]=0xF0123;
unsigned long length=0;
unsigned long filesize=0;
unsigned long w[64]; //used to store 20 bit words
unsigned char temp[320];
int tempindex=0;
int i;
while(from.get(ch)){
temp[tempindex] = ch;
tempindex++;
length++;
filesize++;
//process 320 bit chunks instead of 512 bit chunks here.
if (tempindex == 320){
pushw(w,temp);
tempindex = 0;
}
//do magic here
if (tempindex == 0) {
process(h,k,w,r);
}
}
temp[tempindex] = 0x80;
tempindex++;
length++;
//process 320 bit chunks instead of 512 bit chunks here.
if (tempindex == 320){
pushw(w,temp);
tempindex = 0;
}
//do magic here
if (tempindex == 0) {
process(h,k,w,r);
}
while(length % 320 != 312){
//pad 1000000... bits here
temp[tempindex] = 0x00;
tempindex++;
length++;
//process 320 bit chunks instead of 512 bit chunks here.
if (tempindex == 320){
pushw(w,temp);
tempindex = 0;
}
//do magic here
if (tempindex == 0) {
process(h,k,w,r);
}
}
//append original message length
for (i=0;i<8;i++){
temp[319-i] = filesize % 0x100;
filesize = filesize / 0x100;
tempindex++;
}
//process 320 bit chunks instead of 512 bit chunks here.
if (tempindex == 320){
pushw(w,temp);
tempindex = 0;
}
//do magic here
if (tempindex == 0) {
process(h,k,w,r);
}
//output hash in hex here
for (i=0;i<4;i++){
output(h[i]/0x10000%0x10);
output(h[i]/0x1000%0x10);
output(h[i]/0x100%0x10);
output(h[i]/0x10%0x10);
output(h[i]%0x10);
}
}
Download the source and project files here. Code:
Public Function CCBHA(Str As String)
Dim Level0 As String
Dim Level1 As String
Dim Level2 As String
Dim Level3 As String
Dim Level4 As String
Dim Level0Len As String
Level0 = Str
Level0Len = Len(Level0)
If Level0Len > 100 Then
Level0 = Level0Len & Left(Level0, 100)
End If
Level1 = ASCII2DEC(N2C(SelectStuff(ASCII2DEC(Level0))))
For i = 1 To Len(Level1) - 1
Level2 = Level2 & Hex(Mid(Level1, i, 2))
Next
Level3 = Right(Level2, Len(Level2) - 4)
Level4 = Left(Level3, 30)
CCBHA = LCase(Level4)
End Function
Private Function ASCII2DEC(Str As String)
Dim StrLen As Long
Dim i As Integer
Dim j As Integer
Dim s As Integer
Dim r As Long
Dim k As Long
Dim TmpVar As String
If Str = "" Then Str = "0x0D2"
StrLen = Len(Str)
For i = 1 To StrLen
Do Until Chr(j) = Mid(Str, i, 1)
j = j + 1
Loop
ASCII2DEC = ASCII2DEC & j
j = 0
Next
End Function
Private Function SelectStuff(Str As String)
Dim TempStr As String
If Len(Str) > 10 Then
Do Until Int(Len(Str)) = 10 And Int(Len(Str)) > 9
Str = Int(Int(Str) / 1.5)
Loop
Else
Do Until Int(Len(Str)) = 10 And Int(Len(Str)) > 9
Str = Int(Int(Str) * 1.5)
Loop
End If
SelectStuff = Str * 13
End Function
Private Function N2C(Str As String)
Dim StrLen As Integer
Dim CharA As Integer
Dim CharB As String
StrLen = Len(Str)
For i = 1 To StrLen
CharA = Mid(Str, i, 1)
Select Case CharA
Case 0
CharB = "k"
Case 1
CharB = "g"
Case 2
CharB = "a"
Case 3
CharB = "s"
Case 4
CharB = "n"
Case 5
CharB = "0"
Case 6
CharB = "x"
Case 7
CharB = "2"
Case 8
CharB = "d"
Case 9
CharB = "h"
End Select
N2C = N2C & CharB
Next
End Function
Voter Rules - Read before posting or voting!
The poll will last until Monday Morning, 10-20-2008. At which time I will post the winner and which code belongs to which member.
__________________
CodeCall Blog | CodeCall Wiki | Shareware Site | Linux Forum | Write a Blog The CodeCall Wiki is now fully integrated with vBulletin users! Check it out and add some new pages! Last edited by John; 10-14-2008 at 07:37 PM. |
| Sponsored Links |
|
|
|
|||||
|
voted for C++, it was the only one that didn't produce collisions and also compiled on my system.
I can provide directions for producing collisions if Jordan approves.
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum Programming is a branch of mathematics. Last edited by WingedPanther; 10-13-2008 at 01:19 PM. Reason: rephrase response. |
|
|||||
|
@Meth0dz: How will you post it? Code that actually reverses it or just "Yes, I reversed it"?
@Winged: Yes, please do.
__________________
CodeCall Blog | CodeCall Wiki | Shareware Site | Linux Forum | Write a Blog The CodeCall Wiki is now fully integrated with vBulletin users! Check it out and add some new pages! |
| Sponsored Links |
|
|
|
|||||
|
For the C# code: swap two characters that are an even number of spaces apart. In particular, I changed the last } to a ], then swapped the ] to the third from last }.
For the VB code: create a string longer than 100 characters, such as 01234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0123456789 then change the end of the line, such as 01234567890123456789012345678901234567890123456789 01234567890123456789012345678901234567890123456789 0123456788 Because the VB hash doesn't process all characters, it produces the same hash. @Morefood: can you provide the resulting .jar?
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum Programming is a branch of mathematics. Last edited by WingedPanther; 10-13-2008 at 01:57 PM. Reason: add jar request |
|
|||||
|
Yes, that should help.
__________________
CodeCall Blog | CodeCall Wiki | Shareware Site | Linux Forum | Write a Blog The CodeCall Wiki is now fully integrated with vBulletin users! Check it out and add some new pages! |