def compute(self, message): self.ihvs = list(self.IVs) message += self.pad(message) for block in _misc.as_bytes_blocks(message, self.block_length / 8): self.process_block(block) self.finalize() return self
def checksum(message): checksum_bytes = [0 for i in xrange(16)] previous = 0 for block in as_bytes_blocks(message, 16): for i, char in enumerate(block): # careful, RFC1319 is wrong there. - rfcc209 # Set C[j] to S[c xor L] # should be # Set C[j] to (C[j] xor S[c xor L]) checksum_bytes[i] = checksum_bytes[i] ^ Md2_u.pi_subst[ord(char) ^ previous] previous = checksum_bytes[i] checksum_string = str().join(chr(i) for i in checksum_bytes) return checksum_string
def checksum(message): checksum_bytes = [0 for i in xrange(16)] previous = 0 for block in as_bytes_blocks(message, 16): for i, char in enumerate(block): # careful, RFC1319 is wrong there. - rfcc209 # Set C[j] to S[c xor L] # should be # Set C[j] to (C[j] xor S[c xor L]) checksum_bytes[i] = checksum_bytes[i] ^ Md2_u.pi_subst[ ord(char) ^ previous] previous = checksum_bytes[i] checksum_string = str().join(chr(i) for i in checksum_bytes) return checksum_string
def compute(self, message): self.ihvs = list(self.IVs) message += self.pad(message) block_bytes = [0 for i in xrange(16)] blocks = as_bytes_blocks(message, 16) for block in blocks: xor = bytes([0 for i in xrange(16)]) block_bytes = [ord(i) for i in block] for i in xrange(16): xor[i] = self.ihvs[i] ^ block_bytes[i] previous = Byte(0) for round_ in xrange(18): for l in [self.ihvs, block_bytes, xor]: for k in xrange(16): previous = l[k] = l[k] ^ Md2_u.pi_subst[previous] previous = previous + round_ return self