here’s a rerun of the parity code

#!/usr/bin/python
import random

"""
expand(message, length):
for every bit in message:
make length - 1 random bits, shift by 1, calculate their parity
if it matches the bit, add it to the result (else, add 1 to the random bits, add to result)
shift the result by length
condense(message, length):
for every chunk of length in message:
calculate the chunk's parity
add it to the answer
shift the answer by 1

must pull in arbitrary data types.
"""

def funk(a):
print("{0:08b}".format(a))

def parityOf(a):
a = int(a)
parity = 0
while (a):
parity = ~parity
a = a & (a - 1)
if parity == -1:
return 1
return parity
global initial
initial = 0
def expand(a,length):
result = 0
pending = int(a.encode('hex'),16)
initial = pending
biggest = 2**length-1
print("biggest number out of {} length is: {}, bit length is {}".format(length,biggest,pending.bit_length()))
bits = [(pending >> position) & 1 for position in range(pending.bit_length())]
print("run for:{}".format(len(bits)))
for bit in bits:
requested = parityOf(bit)
bits = random.randint(0,biggest)
bits = bits << 1
parity = parityOf(bits)
if parity == requested: addto = bits + 0
else: addto = bits + 1
result = result << length
result = result + addto
print('final result:')
funk(result)
bits = [(pending >> position) & 1 for position in range(pending.bit_length())]
print("our individual bits are {}".format(bits))
print(str(result))
return str(result).decode('hex')
def condense(a,length):
result = 0
pending = int(a.encode('hex'),16)
print('beginning with: {}, or {}'.format(a, pending))
print('reducing length from {} to {}'.format(len(a),len(a)/length))
bits = [(pending >> position) & 1 for position in range(pending.bit_length())]
print("our individual bits are {}".format(bits))
trials = []
for i in range(0, len(bits), length):
reslist = bits[length*i:length*i+length]
res = 0
for b in reslist:
print("the bit is: {}".format(b))
res << 1
res = res + b
print("internally our segment is {} with a length {}".format(res,res.bit_length()))
trials.append(res)
print(trials)
print('trials to work through: {}'.format(trials))
for bit in trials:
print(bit)
result = result << 1
result = result + parityOf(bit)
print('final condensing: {}'.format(result))
funk(result)
if initial == result:
print("on the right track")
else:
print("intial: {} result: {}".format(initial, result))
return str(result).decode('hex')
funk(int("abc".encode('hex'),16))
result = expand("abc",8)
print("our function resulted in {} with a length of {}".format(result, len(result)))
result = condense(result,8)
print(result)