## "Fossies" - the Fresh Open Source Software Archive

### Source code changes of the file "src/bundle/AfSplitter.py" betweenrevelation-0.5.3.tar.xz and revelation-0.5.4.tar.xz

AfSplitter.py  (revelation-0.5.3.tar.xz):AfSplitter.py  (revelation-0.5.4.tar.xz)
skipping to change at line 58 skipping to change at line 58
def _diffuse(block, size, digest): def _diffuse(block, size, digest):
"""Internal function to diffuse information inside a buffer""" """Internal function to diffuse information inside a buffer"""
# Compute the number of full blocks, and the size of the leftover block # Compute the number of full blocks, and the size of the leftover block
digest_size = hashlib.new(digest).digest_size digest_size = hashlib.new(digest).digest_size
full_blocks = int(math.floor(float(len(block)) / float(digest_size))) full_blocks = int(math.floor(float(len(block)) / float(digest_size)))
# hash the full blocks # hash the full blocks
ret = "" ret = b""
for i in range(0, full_blocks): for i in range(0, full_blocks):
hash = hashlib.new(digest) hash = hashlib.new(digest)
hash.update(struct.pack(">I", i)) hash.update(struct.pack(">I", i))
hash.update(block[i*digest_size:(i+1)*digest_size]) hash.update(block[i*digest_size:(i+1)*digest_size])
ret += hash.digest() ret += hash.digest()
# Hash the remaining data # Hash the remaining data
hash = hashlib.new(digest) hash = hashlib.new(digest)
hash.update(struct.pack(">I", full_blocks)) hash.update(struct.pack(">I", full_blocks))
skipping to change at line 81 skipping to change at line 81
return ret return ret
def AFSplit(data, stripes, digesttype='sha1'): def AFSplit(data, stripes, digesttype='sha1'):
"""AF-Split data using digesttype. Returned data size will be len(data) * s tripes""" """AF-Split data using digesttype. Returned data size will be len(data) * s tripes"""
blockSize = len(data) blockSize = len(data)
rand = Random.new() rand = Random.new()
bufblock = * blockSize bufblock = [0] * blockSize
ret = "" ret = b""
for i in range(0, stripes-1): for i in range(0, stripes-1):
# Get some random data # Get some random data
ret += r ret += r
bufblock = _xor(r, bufblock) bufblock = _xor(r, bufblock)
bufblock = _diffuse(bufblock, blockSize, digesttype) bufblock = _diffuse(bufblock, blockSize, digesttype)
ret += _xor(bufblock, data) ret += _xor(bufblock, data)
return ret return ret
def AFMerge(data, stripes, digesttype='sha1'): def AFMerge(data, stripes, digesttype='sha1'):
"""AF-Merge data using digesttype. len(data) must be a multiple of stripes" "" """AF-Merge data using digesttype. len(data) must be a multiple of stripes" ""
if len(data) % stripes != 0: if len(data) % stripes != 0:
raise ValueError("ERROR: data is not a multiple of strips") raise ValueError("ERROR: data is not a multiple of strips")
blockSize = len(data) / stripes blockSize = len(data) // stripes
bufblock = * blockSize bufblock = [0] * blockSize
for i in range(0, stripes - 1): for i in range(0, stripes - 1):
bufblock = _xor(data[i*blockSize:(i+1)*blockSize], bufblock) bufblock = _xor(data[i*blockSize:(i+1)*blockSize], bufblock)
bufblock = _diffuse(bufblock, blockSize, digesttype) bufblock = _diffuse(bufblock, blockSize, digesttype)
return _xor(data[(stripes-1)*blockSize:], bufblock) return _xor(data[(stripes-1)*blockSize:], bufblock)
End of changes. 5 change blocks.
5 lines changed or deleted 5 lines changed or added