@@ -0,0 +1,1442 @@
+import math%0A%0Adef FindKeyBits(n):%0A  keyBits=%5B%5D%0A  pad = int(math.ceil(math.log(n)/math.log(2)))%0A  for i in xrange(1, n+1):%0A    b = %22%7B0:b%7D%22.format(i)%0A    b=b.zfill(pad)%0A    keyBits.append(b)%0A  return keyBits%0A%0Adef IsPowerOf2(x):%0A  return ((x&(x-1))==0)%0A%0Adef XOR(a, b):%0A  return str(int(a)%5Eint(b))%0A%0Adef FindParityCount(m):%0A  r = math.ceil((math.log(m)/math.log(2))+1)%0A  return int(r)%0A%0Adef CalculateParity(keyBits, data, parityTrack):%0A  parity = '0'%0A  pbCount = 0%0A  for elem in keyBits:%0A    if not IsPowerOf2(int(elem,2)):%0A      if elem%5B-parityTrack%5D=='1':%0A        parity = XOR(parity, data%5BpbCount-int(elem,2)%5D)%0A    else:%0A      pbCount+=1%0A  return parity%0A%0Adef ComputeHamming(data):%0A  dataLen = len(data)%0A  parityCount = FindParityCount(dataLen)%0A  hammingLen = dataLen + parityCount%0A  keyBits = FindKeyBits(hammingLen)%0A  hammingCode = %5B%5D%0A  dataTrack = -1%0A  parityTrack = 1%0A  for i in xrange(1, hammingLen+1):%0A    if IsPowerOf2(i):%0A      parity = CalculateParity(keyBits, data, parityTrack)%0A      hammingCode.append(parity)%0A      parityTrack+=1%0A    else:%0A      hammingCode.append(data%5BdataTrack%5D)%0A      dataTrack-=1%0A  hammingCode.reverse()%0A  for i in hammingCode:%0A    print i, %0A%0A%0Adef main():%0A  print '%5Cn'%0A  inputList=%5B%5D%0A  for i in xrange(int(raw_input())):%0A    inputList.append(raw_input())%0A  i = 1%0A  for data in inputList:%0A    print '%5CnThe Hamming encoded word for',i,'is : ',%0A    ComputeHamming(data)%0A    i+=1%0A%0Aif __name__ == '__main__':%0A  main()%0A

Add HammingCode.py