%Algorithm to encrypt an Audio file in Matlab written by Farheen Bibi (2013), adapted to Matlab 2014b by RC
[a, SR] = audioread('years.wav');                                                                               %sound to be encrypted
pl_a = audioplayer(a, 44100);
playblocking(pl_a)
                                                                                                                 %play sound
ENC=input('Enter the amount of distortion value between 1-6 to Encrypt:');
a1=a';                                                                                                                          %changes row to column & VV
[y,u]=size(a1);                                                                                                            %give dimensions.(y=col, u=row)

[c, SR]=audioread('synthvcs3.wav');                                                                                          %noise
c1=c';
c2=c1(1:u*ENC);                                                                                                        %extending noise samples acc. to ENC no.
[j,k]=size(c2);

%ENCRYPTION
n1=1;           %variable
for(m=1:u)    %this loop embed information audio to noise
c2(1,n1)=a1(1,m);    %skipping (ENC-1) samples
n1=n1+ENC;
end

c3=c2';
%sound(c3);
pl_c = audioplayer(c3, 44100);
playblocking(pl_c)              %play encrypted sound

%DECRYPTION
w=zeros(1,u);
DCP=input('Enter the amount of distortion to Decrypt:');

n2=1;                           %variable
for(m=1:u)                  %this loop changes samples of zero matrix w
w(1,m)=c2(1,n2);       %with encrypted audio c2 samples, starting
n2=n2+DCP;              %from 1 & skipping (DCP-1) samples of c2.
end
w1=w';
%sound(w1)                 %final decrypted sound
pl_w = audioplayer(w1, 44100);
playblocking(pl_w)