יום חמישי, 9 במאי 2013

Toy Tetragraph Hash

At my  Security Computer course i was asked in one of my exercise to build a machine that imitiate Hash procedure.But instead of bits the hash input is chars.

The mechanism of the hash function is illustrated here:

and that is the small python code to compute the hash function:


import numpy as np

text="I leave twenty million dollars to my friendly cousin Bill"
text="AYHG" +"A"*12 +"A"*32
print(text)
#this is the input for the tth...
IV=(0,0,0,0) # initial Vector


def shiftlist(l,n):  #this function do the shift list
    l=list(l)
    Shifted=l[n:]+l[:n]
    return Shifted


text=text.replace(" ",'') #ignore spaces
text=text.lower()         #ignore case sensitive
text=[ord(c)-97 for c in text] #convert text to ascii

lenght = len(text) # move 16 char every time..
for x in range(int(lenght/16)):

    Matrix =np.array(text[16*x:16*(x+1)]).reshape(4,4) #convert 16 string to 4X4 matrix
    
    sumMatrix=(Matrix.sum(axis=0)) #sum the Matrix
    for x in range(3):   # rotate each row
        Matrix[x,:] =shiftlist(Matrix[x,:],x+1)

    #ugly last row rotation:
    temp =Matrix[3,0];Matrix[3,0]=Matrix[3,3];Matrix[3,3]=temp
    temp =Matrix[3,1];Matrix[3,1]=Matrix[3,2];Matrix[3,2]=temp

    ##Sum the  columns + the rotate colums +IV
    
    IV=(IV +(Matrix.sum(axis=0))+sumMatrix)%26
    

#now IV is the output
for i in range(4):  #print the string
    print(chr(IV[i]+97),end=" ")

#######################################################

The next challange is to find a collision.
i leave it as a riddle for you.

2 תגובות:

  1. Lucky Club Casino Site - Online Casino | BetUS Sportsbook
    Bet online luckyclub with the best USA sportsbook, online casino or online sportsbook at Lucky Club Casino. Lucky Club Casino is open 24 hours a day and includes

    השבמחק
  2. Casino, Hotel & Casino, Waterloo - Mapyro
    The 구미 출장안마 Casino, Hotel & 삼척 출장안마 Casino is the perfect 충청북도 출장샵 place to work 하남 출장마사지 on your next project. Located 남원 출장샵 in Waterloo, Ontario, Canada, the Casino is a leisurely,

    השבמחק