Salut

En réponse a un projet universitaire sur la stéganographie avec le fichiers wav, j'ai trouvé un code MATLAB sur internet et je l'ai modifié un peu.
Mon problème est qu'il fonctionnne avec certains fichiers wav et pas d'autres, il y donne comme résultats des fichiers corrompus.

En faisant plusieurs essais, le resultat change en modifiant le "unintxx" dans la partie (dta) concernant la lecture et de la réecriture du fichier wav.

Quelqu'un a-t-il un idée? des suggestions pour l'amelioration.
C'est la première fois que j'utilise MATLAB, niveau débutant.
Merci

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
msg=input('Entrez votre message\n','s');  
 
[filename, pathname] = uigetfile('*.wav','Select a file');        
[y,fs]=audioread([pathname filename],[1 2]);
 
%open a wav file for hidding text
fid1=fopen([pathname filename],'r');
 
%first 40 bytes make wav header,store the header column array with 40 elements
header=fread(fid1,40,'uint8=>char'); 
 
%41st byte to 43rd byte,length of wav data samples (unint16 is 2 bytes)
data_size=fread(fid1,1,'uint16');
 
%copy the 16 bit wav data samples starting from 44th byte
[dta,count]=fread(fid1,inf,'uint32');   
 
%count is the number of characters read in audio
 
%close the file only wav data samples are sufficient to hide the text 
fclose(fid1);
 
% we will hide the data in the lsb
lsb=1;
 
msg_double=double(msg);       %convert the msg to double
msg_bin=de2bi(msg_double,8);  %then convert message to binary 8 columns matrix
[m,n]=size(msg_bin);          %size of message binary
                              %m is the number of characters
                              %n number of rows in the matrix (using 8)
msg_bin_re=reshape(msg_bin,m*n,1);  %reshape the message binary in a column vector   
m_bin=de2bi(m,8)';
n_bin=de2bi(n,8)';
len=length(msg_bin_re);       %length of message binary (len=m*n)
 
len_bin=de2bi(len,16)';       %convert the length to binary on 16 rows
 
%if number of characters in message is more than count => message is too
%big (m>count0)
 
 
%hide identity in first 8 wav data samples, identity is used as a security
%key
 
key=input('Entrez un mot de passe\n','s');   %get  the key
key_d = double(key);                       %convert it to double
key_b = de2bi(key_d,8);             %convert it to binary   
[o,p]=size(key_b);
 
identity=reshape(key_b,o*p,1);          %reshape it as a single row array
dta(1:8)=bitset(dta(1:8),lsb,identity(1:8));          %hide it
 
%hide binary length of message from 9th to 24 th sample 
dta(9:16)=bitset(dta(9:16),lsb,m_bin(1:8));
dta(17:24)=bitset(dta(17:24),lsb,n_bin(1:8));                              
 
%hide the message binary starting from 25th position of wave data samples
dta(25:24+len)=bitset(dta(25:24+len),lsb,msg_bin(1:len)');
 
%open a new wav file in write mode
fid2=fopen('HiddenMessageAudio.wav','w');
 
%copy the header of original wave file
fwrite(fid2,header,'uint8');
fwrite(fid2,data_size,'uint16');
 
%copy the wav data samples with hidden text
fwrite(fid2,dta,'uint32');
fclose(fid2);