Hi Neshant,
your code is almost correct except a couple of mistakes.
In read-write script you need to provide encripted message as input to the decoder function.
i.e.
decoded_text=decoder(encoded_text,key);
And in the decoder function, your key is already in binary format so you don't need to convert it again to binary, which is causing a mismatch in the vector sizes.
%%Decoder Script
function message= decoder(ciphertext,key)
n=length(ciphertext) ;
ciphertext=uint8(ciphertext);
%bkey=de2bi(key,8,'left-msb');
textmessage =' ';
for m = 1: n
message_binary=xor(de2bi(ciphertext(m),8,'left-msb'),key);
message_dec=bi2de(message_binary,'left-msb');
textmessage(m)= char(message_dec); %%<--This line is the problem
end
message=textmessage;%return key from encoder
Cheers.
Deepak