-
Notifications
You must be signed in to change notification settings - Fork 0
/
charStringtoBin.m
33 lines (33 loc) · 1.03 KB
/
charStringtoBin.m
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
function [ bin ] = charStringtoBin( charStr )
% charStringtoBin convert string of characters to binary returns a 2D array
% It takes a input of String of charcacters, traverses the characters and
% converts to binary in row-wise. It should be noted that the bit length
% of the ASCII value is not always equals, it may be 6 bit or more. This
% is returned end of the function.
sz = length(charStr);
maxbit = 0;
for j=1:sz
if length(de2bi(int16(charStr(j))))>maxbit
maxbit = length(de2bi(int16(charStr(j))));
end
end
% To find the maximum and minimum bits of the characters being entered as
% Stego Text
binarray = zeros(sz,maxbit);
binarray (binarray==0)=4;
% Initialise a number other than 0 and 1 in array, to identify whether it
% is a bit. Here we took it as 4.
for i=1:sz;
bintemp = de2bi(int16(charStr(i)));
j=1;
k = 1;
while j<=length(bintemp)
binarray(i,j) = bintemp(k);
j=j+1;
k=k+1;
end
end
binarystring = binarray(:);
binarystring (binarystring==4)=0;
bin = binarystring';
end