Пример #1
0
func NewTruncatedMD4() *TruncatedMD4 {
	return &TruncatedMD4{md4.New(hashSize), hashSize}
}
Пример #2
0
func main() {
	m1 := ToBytes("4d7a9c8356cb927ab9d5a57857a7a5eede748a3cdcc366b3b683a0203b2a5d9fc69d71b3f9e99198d79f805ea63bb2e845dd8e3197e31fe52794bf08b9e8c3e9")
	m1p := ToBytes("4d7a9c83d6cb927a29d5a57857a7a5eede748a3cdcc366b3b683a0203b2a5d9fc69d71b3f9e99198d79f805ea63bb2e845dc8e3197e31fe52794bf08b9e8c3e9")
	m2 := ToBytes("4d7a9c8356cb927ab9d5a57857a7a5eede748a3cdcc366b3b683a0203b2a5d9fc69d71b3f9e99198d79f805ea63bb2e845dd8e3197e31fe5f713c240a7b8cf69")
	// Swap little/big endian
	for i := 0; i < len(m1); i += 4 {
		for j := 0; j < 2; j++ {
			i1 := i + j
			i2 := i + 3 - j
			c := m1[i1]
			m1[i1] = m1[i2]
			m1[i2] = c
			c = m2[i1]
			m2[i1] = m2[i2]
			m2[i2] = c
			c = m1p[i1]
			m1p[i1] = m1p[i2]
			m1p[i2] = c
		}
	}
	m1pp := bytes.Repeat([]byte{'x'}, len(m1))
	GetPair(m1, m1pp)
	// Verify that my Pair method works
	if string(m1pp) != string(m1p) {
		log.Printf("%x", m1pp)
		log.Printf("%x", m1p)
		return
	}
	if !CheckConditions(m1) {
		return
	}
	if !CheckConditions(m2) {
		return
	}
	// CheckConditions(m2)
	// md1 := md4.New(16)
	// md2 := md4.New(16)
	// // md1.Write(m1)
	// // md2.Write(m2)
	// // log.Printf("%x", md1.Sum(nil))
	// // log.Printf("%x", md2.Sum(nil))

	// m := []byte(strings.Repeat("x", 64))
	// log.Printf("%x", m)
	// CheckConditions(m)
	// Correct(m, 1)
	// Correct(m, 2)
	// Correct(m, 4)
	// Correct(m, 8)
	// Correct(m, 16)
	// Correct(m, 32)
	// log.Printf("%x", m)
	// CheckConditions(m)

	log.Printf("Looking for a collision")
	M0 := []byte(strings.Repeat("a", 64))
	M := make([]byte, len(M0))
	Mp := []byte(strings.Repeat("x", 64))
	rand.Seed(1)
	for trials := 1; ; trials++ {
		for i := 0; i <= 21; i++ {
			Correct(M, i)
		}
		if !CheckConditions(M) {
			return
		}
		GetPair(M, Mp)
		dig := md4.New(16)
		dig.Write(M)
		m := dig.Sum(nil)
		dig = md4.New(16)
		dig.Write(Mp)
		mp := dig.Sum(nil)
		if string(m) == string(mp) {
			log.Printf("%x: %x", m, M)
			log.Printf("%x: %x", mp, Mp)
			log.Printf("%d tries", trials)
			return
		}
		if trials%1000000 == 0 {
			log.Printf("%d tries", trials)
		}
		for i, _ := range M0 {
			M[i] = byte(rand.Uint32())
		}
		//nextMessage(M0)
		//copy(M, M0)
	}

}