al3x (owner)

Revisions

gist: 108216 Download_button fork
public
Public Clone URL: git://gist.github.com/108216.git
Kember.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import java.security.MessageDigest
import scala.actors.Actor
import scala.actors.Actor._
import scala.util.Random
 
class DigestComparisonActor extends Actor {
  val md5 = MessageDigest.getInstance("MD5")
  val rand = new scala.util.Random()
  var byteArray = new Array[Byte](32)
 
  def printHex(digestBytes: Array[Byte]) {
    var hex = new StringBuffer()
 
    for (byte <- digestBytes) {
      val hexByte = byte & 0xFF
      if (hexByte < 0x10) hex.append("0")
      hex.append(Integer.toHexString(hexByte))
    }
 
    println(hex)
  }
 
  def act() {
    loop {
      rand.nextBytes(byteArray)
      md5.update(byteArray, 0, byteArray.length)
 
      val randomBytes = byteArray
      val digestBytes = md5.digest()
 
      if (randomBytes deepEquals digestBytes) {
        printHex(digestBytes)
        exit()
      }
    }
  }
}
 
object Kember {
  val cpus = 4 // edit for number of cores on your system
 
  def main(args: Array[String]) {
    for (cpu <- 1 to cpus) {
      val dca = new DigestComparisonActor
      dca.start()
    }
  }
}