function bsc(infile,outfile,p)
%% Read data from a file as bits
disp(['Reading file ',infile]);
f=fopen(infile,'r');
A=fread(f,inf,'ubit1');
fclose(f);
disp(['Read ',num2str(length(A)), ' bits']);
%% Convert to Galois array in GF(2)
message=gf(A);
%% Model symmetric binary channel by adding a random GF(2) vector
disp(['Target error rate is ', num2str(p)]);
err=gf(rand(size(message))<=p);
%% Add error to the message, to simulate received message
received=message+err;
%% Find actual error rate
difference=received-message;
difference=difference ~= 0;
rate=sum(difference(:))/length(message);
disp(['Actual error rate is ', num2str(rate)]);
%% Write the corrupted file 
disp(['Writing file ',outfile]);
f=fopen(outfile,'wb+');
B=received==gf(1);
fwrite(f,B,'ubit1');
fclose(f);

