%% File: paritydecoder.m
%% Read data from a file as bits
%f=fopen('coriolan.txt','r');
f=fopen('coriolan.bin','r');
A=fread(f,inf,'uint8');
fclose(f);
disp(['Read ',num2str(length(A)), ' bits']);
%% Construct parity-generating function
parityfun=@(x) bitand(x,127);
%% Construct parity lookup table
lutstrip=arrayfun(parityfun,0:255);
f=plot(lutstrip,'.');
print('lutstrip','-dpng');
%% Strip parity from data
B=lutstrip(A+1);
%% Write the recovered file
f=fopen('coriolan_d.txt','wb+');
fwrite(f,B,'uint8');
fclose(f);


