0% found this document useful (0 votes)
14 views9 pages

Exp 4 - Saw

The document outlines the implementation of watermarking algorithms for both text and audio using MATLAB. It details the steps and pseudo code for embedding and extracting watermarks while maintaining the quality of the original media. The conclusion emphasizes the importance of these techniques in protecting intellectual property and ensuring content authenticity.

Uploaded by

acc.ai.trial
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views9 pages

Exp 4 - Saw

The document outlines the implementation of watermarking algorithms for both text and audio using MATLAB. It details the steps and pseudo code for embedding and extracting watermarks while maintaining the quality of the original media. The conclusion emphasizes the importance of these techniques in protecting intellectual property and ensuring content authenticity.

Uploaded by

acc.ai.trial
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Alok Mevawala SAW

ET21BTEC037

EXP 4

AIM - Implementation of watermarking algorithm for text and audio.

PART-A - Implementation of watermarking algorithm for text

THEORY
Watermarking in steganography involves embedding information (watermark)
into a carrier medium (like text, images, or audio) in such a way that the
watermark is not easily detectable and the quality of the original medium is
preserved. Here’s a basic outline and example of how you might implement a
watermarking algorithm for text using MATLAB.

ALGORITHM:
Steps:
1. Initialize an empty string for watermarkedText.
2. Determine the positions to insert the watermark characters. For example,
if the watermark is WATERMARK, choose evenly spaced positions in the
originalText.
3. Loop through each character of originalText:
4. For each character, check if it’s time to insert a watermark character
(based on the chosen positions).
5. If it’s time to insert, add the watermark character to watermarkedText.
6. Add the original character to watermarkedText.
7. If there are remaining watermark characters after processing the original
text, append them to the end of watermarkedText.
8. Return watermarkedText.

PSEUDO CODE:
Function EmbedWatermark(originalText,

watermark): binaryWatermark =
Alok Mevawala SAW
ET21BTEC037

ConvertToBinary(watermark) watermarkedText =

originalText

watermarkIndex = 0

For each character in originalText:

If watermarkIndex >= Length(binaryWatermark):

Break

currentBit = binaryWatermark[watermarkIndex]

If currentBit == '1': watermarkedText


= ReplaceCharacter(watermarkedText, character,
Uppercase(character))

Else: watermarkedText =
ReplaceCharacter(watermarkedText, character,
Lowercase(character)) watermarkIndex += 1

Return watermarkedText

CODE:
(embedding .txt file)
FID = fopen('Name.txt', 'rb'); %opening text file
Str = fread(FID, [1, inf], 'char'); %reading text
file fclose(FID); %closing the file
Str=uint16(Str); %converting to 16 bit numbers for proper
calculation x=imread('Cameraman.png'); %reading the image file
x=uint16(x); %conversion to 16 bit
[x_row,x_col]=size(x);
c=numel(Str); %counting
characters a=1;
%encrypting loop for
i=1:x_row for
j=1:x_col if(a<=c)
if(x(i,j)+Str(a)>255)
temp=x(i,j)+Str(a)-
256; else
Alok Mevawala SAW
ET21BTEC037

temp=x(i,j)+Str(a);
end
z(i,j)=uint8(temp);
else
z(i,j)=uint8(x(i,j)
); end a=a+1;
end
end
imwrite(z,'encrypted.png'); %writing the encrypted data as pixels
in image imshow("cameraman.tif"); title("original image"); figure();
imshow("encrypted.png"); title("watermarked image");

OUTPUT:
Alok Mevawala SAW
ET21BTEC037

(for decryption)
x=imread('encrypted.png'); %reading encrypted
image y=imread('Cameraman.png'); %reading non-
encrypted image x=uint16(x); %16 bit conversion
y=uint16(y); %16 bit conversion [x_row,
x_col]=size(x); b=0;k=1; %decrypting loop for
i=1:x_row for j=1:x_col if(x(i,j)>=y(i,j))
a=x(i,j)-y(i,j); else
a=256+x(i,j)-
y(i,j); end
if(a~=0)
z(k)=uint8(a);
k=k+1; else b=1;
break; end end
if(b==1) break; end
end
fid=fopen('decrypted.txt','w'); %creating text file to write decrypted
data for i=1:k-1
fprintf(fid,'%c',z(i)); %writing to
file end

OUTPUT:
Alok Mevawala SAW
ET21BTEC037

PART B - Implementation of watermarking algorithm for audio.

THEORY:
Audio watermarking involves embedding information into audio signals while
maintaining their perceptual quality. Techniques like Least Significant Bit
(LSB), spread spectrum, and phase modulation modify the audio in ways that
are imperceptible to listeners. The process utilizes psychoacoustic principles to
place data in less audible regions, ensuring that the watermark is robust against
compression and other alterations. The primary goal is to protect intellectual
property by embedding data that can be extracted later, balancing invisibility
with resilience against degradation.

ALGORITHM:
Input Audio File: Load the original audio file (WAV format is often used for
simplicity).
Watermark Creation: Create the watermark data you want to embed (e.g., a
binary string representing a message).
Preparation of Watermark:
• Convert the watermark message into binary format.
• Ensure the watermark size does not exceed the available space in the
audio file.
Audio Analysis:
Alok Mevawala SAW
ET21BTEC037

• Extract the audio samples from the audio file.


• Determine the number of audio samples available for watermarking.

Embedding the Watermark:


• For each bit of the watermark:
o Modify the least significant bit of the corresponding audio sample
to match the watermark bit. o If the watermark bit is 1, set the LSB of
the audio sample to 1; if it is 0, set it to 0.
Output Watermarked Audio: Save the modified audio samples to create a new
watermarked audio file.
Watermark Extraction:
• Load the watermarked audio file.
• Extract the audio samples and read the LSBs of the samples used for
watermarking.
• Reconstruct the watermark from the extracted bits.

Verification: Compare the extracted watermark with the original watermark to


verify the integrity and correctness.

PSEUDO CODE:
FUNCTION WatermarkAudio(originalAudio, watermark,

outputAudio): Load originalAudio into audioData

binaryWatermark = ConvertToBinary(watermark)

IF LENGTH(binaryWatermark) > LENGTH(audioData):

PRINT "Watermark too large."

RETURN

FOR i FROM 0 TO LENGTH(binaryWatermark) - 1:

sample = audioData[i] sample = SET_LSB(sample,

binaryWatermark[i]) // Modify LSB audioData[i] =

sample
Alok Mevawala SAW
ET21BTEC037

Save outputAudio as audioData

END FUNCTION

FUNCTION ExtractWatermark(watermarkedAudio,

watermarkLength): Load watermarkedAudio into

audioData extractedWatermark = ""

FOR i FROM 0 TO watermarkLength - 1:

sample = audioData[i]

lsb = GET_LSB(sample)

extractedWatermark = extractedWatermark + lsb

RETURN ConvertFromBinary(extractedWatermark)

END FUNCTION

CODE:
% Define file paths
imageFile = 'Cameraman.png'; % Path to your image file
audioFile = 'fantastic.wav'; % Path to your audio file
outputImageFile = 'image_with_audio.png'; % Path to the output image file
% Read the image img =
imread(imageFile);
% Read the audio
[audioData, audioFs] = audioread(audioFile);
% Normalize audio data
audioData = audioData - min(audioData); % Shift to positive
audioData = audioData / max(audioData); % Normalize to [0, 1]
% Convert audio data to binary
audioDataBin = dec2bin(round(audioData *
255), 8); audioDataVec = audioDataBin(:) -
'0'; % Determine available bits in the image
[nRows, nCols, nChannels] = size(img);
numPixels = nRows * nCols * nChannels;
numBitsAvailable = numPixels * 8; % Truncate
audio data if necessary if
Alok Mevawala SAW
ET21BTEC037

length(audioDataVec) > numBitsAvailable


audioDataVec =
audioDataVec(1:numBitsAvailable); disp('Audio
data truncated to fit in the image.'); end
% Embed audio data in the least significant bit of the
image imgWithAudio = img; audioDataIdx = 1; for row =
1:nRows for col = 1:nCols for ch = 1:nChannels
if audioDataIdx <= length(audioDataVec)
% Get current pixel value pixelValue
= imgWithAudio(row, col, ch); %
Modify the least significant bit
imgWithAudio(row, col, ch) = bitset(pixelValue, 1,
audioDataVec(audioDataIdx)); audioDataIdx = audioDataIdx + 1; end end end
end
% Save the image with embedded audio data
imwrite(imgWithAudio, outputImageFile);
disp('Audio data embedded in image successfully.');
% Display the image with embedded audio
imshow(imgWithAudio);
title('Image with Embedded Audio');

OUTPUT:
Alok Mevawala SAW
ET21BTEC037

ORIGINAL AUDIO:

EXTRACTED AUDIO:

CONCLUSION:
Watermarking algorithms for text and audio are essential for protecting
intellectual property and ensuring content authenticity. Text watermarking
embeds hidden information without compromising readability, while audio
watermarking securely incorporates data within sound waves. Both methods
must balance imperceptibility and robustness to withstand processing.
Ultimately, these techniques enhance the integrity and security of digital media,
addressing challenges in copyright protection and digital piracy. Future
advancements will likely focus on improving efficiency and security in
response to ongoing threats.

You might also like