def encrypt(mess_str, key_str): """ Do encryption from string and return string. """ # generating key list (K1...K32) key = cryptBlocks.getBlockFromString(key_str) # splitting message to blocks mess = cryptBlocks.getBlocksFromString(mess_str, blockSize) # for enable encrypting empty message%) if len(mess) == 0: mess.append(0x00) return cryptBlocks.getStringFromBlocks(cryptBlockList(mess, key))
def getHash(src): """ Main function - calculates hash of the given blocks. """ # wtf?! 256 bit, 32 byte! its amazin blockLength = 32 mess = cryptBlocks.getBlocksFromString(src, blockLength) checksumE = 0 # size of message modulo 2^256 lengthL = 0 stepH = 0 if makeReport: i = 0 for m in mess: if makeReport: i += 1 reporter.addBold("Variables list for block N%d "%(i)) reporter.addList(["m = "+hex(m),"H = "+hex(stepH),"L = "+hex(lengthL),"E = "+hex(checksumE)]) stepH = stepFunction(stepH, m) lengthL = (lengthL + cryptBlocks.getSizeOfBlock(m))%(2**(blockLength*8)) checksumE += (checksumE + m)%(2**(blockLength*8)) stepH = stepFunction(stepH, lengthL) stepH = stepFunction(stepH, checksumE) return stepH