Why are there not enough arguments?

I have two files named "data_embedding" and "lsb_enc." The "data_embedding" file runs fine, but when I try to run the "lsb_enc" file I get the following error:
Not enough input arguments.
Error in lsb_enc (line 23)
fid = fopen(wavin,'r');
Please help me fix the error as I am new to Matlab.
%data_embedding
close all; clear all; clc;
[FileName,PathName] = uigetfile({'.wav'}, 'Select cover audio:');
[file.path,file.name,file.ext] = fileparts([PathName FileName]);
wavin = [PathName FileName];
wavout = [file.path '\' file.name '_stego' file.ext];
password = 'mypassword123';
file = 'text.txt';
fid = fopen(file, 'r');
text = fread(fid,'*char')';
fclose(fid);
lsb_enc(wavin, wavout, text, password);
%---------------------------------------------------------------------------------------------
%lsb_enc
function lsb_enc(wavin, wavout, text, pass)
%LSB_ENC LSB Coding technique for WAV files using one bit to hide
%
% INPUT VARIABLES
% wavin : Path of cover signal (wav input)
% wavout : Path of stego signal (wav output)
% text : Message to hide
% pass : Password for encryption
if (nargin<2)
wavout='stego.wav';
end
if (nargin<3)
text = 'Text to be hidden';
end
if nargin<4
pass = 'password123';
end
%Header of wav = 1:40, Length of wav = 41:43, Data part = 44:end
fid = fopen(wavin,'r');
header = fread(fid,40,'uint8=>char');
dsize = fread(fid,1,'uint32');
[cover,len_cover] = fread(fid,inf,'uint16');
fclose(fid);
bin = d2b(double(text),8);
[m,n] = size(bin);
M = d2b(m,40)';
len_msg = m*n;
%Encrypting message with pseudorandom sequence
bitx = 1*xor(reshape(bin,m*n,1), prng(pass, len_msg));
binx = reshape(bitx, m, n);
if (len_cover >= len_msg+48)
%Control variable is encoded(1:8)
control = d2b(mod(sum(double(pass)),256),8)';
cover(1:8) = bitset(cover(1:8),1,control(1:8));
%Length of message is encoded (9:48)
cover(9:48) = bitset(cover(9:48),1,M(1:40));
%Message is encoded (49:48+len)
cover(49:48+len_msg)=bitset(cover(49:48+len_msg),1,binx(1:len_msg)');
%Stego file is saved
out = fopen(wavout,'w');
fwrite(out,header,'uint8');
fwrite(out,dsize,'uint32');
fwrite(out,cover,'uint16');
fclose(out);
else
error('Message is too long!');
end
end
function b = d2b( d, n )
%D2B Minimal implentation of de2bi function
if nargin<2
n = floor ( log (max (max (d), 1)) ./ log (p) ) + 1;
end
d = d(:);
power = ones (length (d), 1) * (2 .^ (0 : n-1) );
d = d * ones (1, n);
b = floor (rem(d, 2*power) ./ power);
end
function out = prng( key, L )
%PRNG Pseudorandom number generator for encryption/decryption
pass = sum(double(key).*(1:length(key)));
rand('seed', pass);
out = (rand(L, 1)>0.5);
end

Respuestas (1)

Image Analyst
Image Analyst el 8 de Jul. de 2023
From data_embedding.m, you call
lsb_enc(wavin, wavout, text, password);
and that runs fine because you've defined the 4 inputs: wavin, wavout, text, password.
However if you try to run lsb_enc by itself without passing in any input variables, like if you simply clicked the green run triangle or typed lsb_enc on the command line, then you'll get that error. It won't automagically "invent" values for those variables to use in the case that they're missing from the input argument list. They need to be passed in.

1 comentario

Image Analyst
Image Analyst el 9 de Jul. de 2023
@Ashwin JB If this Answer solves your original question, then could you please click the "Accept this answer" link to award the answerer with "reputation points" for their efforts in helping you? They'd appreciate it. Thanks in advance. 🙂 Note: you can only accept one answer (so pick the best one) but you can click the "Vote" icon for as many Answers as you want. Voting for an answer will also award reputation points.

Iniciar sesión para comentar.

Productos

Versión

R2022b

Preguntada:

el 8 de Jul. de 2023

Comentada:

el 9 de Jul. de 2023

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by