drawMD5.frink

Download or view drawMD5.frink in plain text format


// This program graphs the output of a hashing function (e.g. MD5, produced
// by changing one bit at a time in the input (using binary reflected Gray
// code) and graphing the output to see if there are visible patterns.

start = 0
end = 255

bits = 128
img = new image[128,end-start+1]
ximg = new image[128,end-start]

for y=start to end
{
   num = messageDigestInt[char[binaryToGray[y]],"MD5"]
   for x=0 to bits-1
      if getBit[num, x] == 0
         img.setPixel[bits-x-1,y,0,0,0]
      else
         img.setPixel[bits-x-1,y,1,1,1]
}

img.show[]
img.write["md5.png"]

for y=start to end-1
{
   n1 = messageDigestInt[char[binaryToGray[y]],"MD5"]
   n2 = messageDigestInt[char[binaryToGray[y+1]],"MD5"]
   num = bitXor[n1,n2]
   for x=0 to bits-1
      if getBit[num, x] == 0
         ximg.setPixel[bits-x-1,y,0,0,0]
      else
         ximg.setPixel[bits-x-1,y,1,1,1]
}

ximg.show[]
ximg.write["md5xor.png"]


Download or view drawMD5.frink in plain text format


This is a program written in the programming language Frink.
For more information, view the Frink Documentation or see More Sample Frink Programs.

Alan Eliasen was born 19305 days, 18 hours, 40 minutes ago.