Tuesday, July 26, 2011

ASCII Encoder and Decoder [Matlab code]


These codings will convert the text file to its equivalent binary format (0s and 1s) and vice versa.

The following Matlab files were included

  • Code.m
  • Encode.m
  • Decode.m

---------------------------------------------------Code.m------------------------------------------------------


spc 00100000
ent 00001010
!   00100001
#   00100011
$   00100100
%   00100101
&   00100110
'   00100111
(   00101000
)   00101001
*   00101010
+   00101011
,   00101100
-   00101101
.   00101110
/   00101111
0   00110000
1   00110001
2   00110010
3   00110011
4   00110100
5   00110101
6   00110110
7   00110111
8   00111000
9   00111001
:   00111010
;   00111011
<   00111100
=   00111101
>   00111110
?   00111111
@   01000000
A   01000001
B   01000010
C   01000011
D   01000100
E   01000101
F   01000110
G   01000111
H   01001000
I   01001001
J   01001010
K   01001011
L   01001100
M   01001101
N   01001110
O   01001111
P   01010000
Q   01010001
R   01010010
S   01010011
T   01010100
U   01010101
V   01010110
W   01010111
X   01011000
Y   01011001
Z   01011010
[   01011011
\   01011100
]   01011101
^   01011110
_   01011111
`   01100000
a   01100001
b   01100010
c   01100011
d   01100100
e   01100101
f   01100110
g   01100111
h   01101000
i   01101001
j   01101010
k   01101011
l   01101100
m   01101101
n   01101110
o   01101111
p   01110000
q   01110001
r   01110010
s   01110011
t   01110100
u   01110101
v   01110110
w   01110111
x   01111000
y   01111001
z   01111010
{   01111011
|   01111100
}   01111101
~   01111110

----------------------------------------------Encode.m-----------------------------------------------------
function encode(File,File2)
%ENCODE  Converting ASCII text to Binary numbers
%   DECODE(FILE,FILE2) where FILE is an input text file consisting of ASCII text and
%       FILE2 is the output file.
%       The code key file (code.m) should be included in the same directory in order
%       for this program to run.
%

wpl=0;
[spc_ent,C0]=textread('code.m','%s %s',2);
[L,C]=textread('code.m','%s %s','headerlines',2);
L=char(L);
FID = fopen(File,'r');
OUT = fopen(File2,'w');
while 1
    tline = fgetl(FID);
    if ~ischar(tline), break, end
    for i=1:size(tline,2)
        x=find(L==tline(i));       
        if isempty(x)==1
            fprintf(OUT,'%s',char(C0(1)));
            fprintf('%s',char(C0(1)));
            wpl=wpl+1;
        else
            fprintf(OUT,'%s',char(C(x)));
            fprintf('%s',char(C(x)));
            wpl=wpl+1;
        end
        if wpl==10, fprintf(OUT,'\n');
            fprintf('\n');wpl=0; end
    end
    fprintf(OUT,char(C0(2)));
     fprintf(char(C0(2)));
    wpl=wpl+1;
end
fclose('all');


-----------------------------------------------decode.m-------------------------------------------------------

function decode(File,File2)

%DECODE  Converting Binary numbers to ASCII text
%   DECODE(FILE,FILE2) where FILE is an input text file consisting of binary numbers
%       and FILE2 is the output ASCII text file.
%  The code key file (code.m) should be included in the same directory in order
%       for this program to run.

t=0;
[spc_ent,C0]=textread('code.m','%s %s',2);
[L,C]=textread('code.m','%s %s','headerlines',2);
L=char(L);
bit = length(char(C(1)));
FID = fopen(File,'r');
OUT = fopen(File2,'w');
while 1
    tline = fgetl(FID);
    if ~ischar(tline), break, end
    for i=1:size(tline,2)/bit
        for j=1:93
            x=isequal(char(C(j,:)),tline(8*i-7:8*i));
            if x==1
                t=j;
            end
        end
        if t~=0
            fprintf(OUT,'%s',L(t));
        elseif tline(8*i-7:8*i)==char(C0(2))
            fprintf(OUT,'\n');  
        elseif tline(8*i-7:8*i)==char(C0(1))
            fprintf(OUT,' ');
        end
        t=0;
    end
end
fclose('all');

Example:
Let  data.txt be the text file with that you wish to convert to binary.

To encode:
encode('data.txt','output.txt')

A file named output.txt will be created on the same directory when u execute the above command.

To decode:

decode('output.txt','decoded.txt')


Sample Text file:  
  • Copy the below contents.
  • Open Notepad.
  • Paste the contents.
  • Save the file (say, test.txt)


Steganography is a technique to hide secret messages in a host media called cover media. The advantage of steganography over cryptography is that messages do not attract attention to attackers and even receivers. Steganography and cryptography are often used together to ensure security of the secret messages.

Hiding capacity is very important for efficient covert communications. In addition, the bit stream truncation makes it difficult to hide information. In this project, a high-capacity steganography scheme is proposed based on DCT and which uses bit-plane encoding procedure, where DCT is used to transform original image (cover image) blocks from spatial domain to frequency domain. An image of size M × N is divided into non overlapping 8 × 8 blocks and a two dimensional Discrete Cosine Transform(2-d DCT) is performed on each of the P = MN / 64 blocks. Then Huffman encoding is also performed on the secret messages/images before embedding and each bit of Huffman code of secret message/image is embedded in the frequency domain by altering the least significant bit of each of the DCT coefficients of cover image blocks.

The experimental results show that the algorithm has a high capacity and a good invisibility. Moreover PSNR of cover image with stego-image shows better results in comparison with other existing steganography approaches. Furthermore, satisfactory security is maintained since the secret message/image cannot be extracted without knowing decoding rules and Huffman table.
With the development of Internet technologies, digital media can be transmitted conveniently over the Internet. However, message transmissions over the Internet still have to face all kinds of security problems. Therefore, how to protect secret messages during transmission becomes an essential issue for the Internet. Encryption is a well-known procedure for secure data transmission. The commonly used encryption schemes include DES (Data Encryption Standard), AES (Advanced Encryption Standard) and RSA. These methods scramble the secret message so that it cannot be understood. However, it makes the message suspicious enough to attract eavesdropper’s attention. Hence, a new scheme, called “steganography”, arises to conceal the secret messages within some other ordinary media (i.e. images, music and video files) so that it cannot be observed. Steganography differs from cryptography in the sense that where Cryptography focuses on concealing the contents of a message, steganography focuses on concealing the existence of a message.
Two other technologies that are closely related to steganography are watermarking and fingerprinting.Watermarking is a protecting technique which protects (claims) the owner’s property right for digital media (i.e. images, music, video and software) by some hidden watermarks. Therefore, the goal of steganography is the secret messages while the goal of watermarking is the cover object itself.
Steganography is the art and science of hiding information in a cover document such as digital images in a way that conceals the existence of hidden data. The word steganography in Greek means “covered writing” (Greek words “stegos” meaning “cover” and “grafia” meaning “writing”). The main objective of steganography is to communicate securely in such a way that the true message is not visible to the observer. That is unwanted parties should not be able to distinguish in any sense between cover-image (image not containing any secret message) and stego-image (modified cover-image that containing secret message). Thus the stego-image should not deviate much from original cover-image. Today steganography is mostly used on computers with digital data being the carriers and networks being the high speed delivery channels.
In order to understand more about how steganography works and indeed to raise awareness of the magnitude of known embedding techniques, some of the most documented steganographic approaches are discussed, splitting them into appropriate groups to illustrate clearly how they differ from each other.
The following techniques are just a handful of the earliest examples of image steganography. Some are easier to implement than others, and some are more robust than others. A simple algorithm is likely to be just as simple to break, whilst the more clever algorithms are harder to break.
A stego-system (steganographic system) in image steganography refers to a system capable of hiding a secret message within an image, such that no third-parties are aware that the message exists. The image that is output from this process is known as a stegogramme, and great care is taken to ensure that this looks as innocent as possible so that the secret message has the best chance of reaching its intended recipient.
However, the stego-system not only refers to encoding the message, it also refers to the system that makes it possible to read the message when it reaches its recipient. The two sub-systems are referred to as the stego-system encoder and the stego-system decoder respectively.
The stego-system encoder is the heart of the steganographic system. It makes it possible to embed a secret message within some cover medium. In the case of image steganography, the encoder will read in a cover image cm,n (where m and n refer to the height and width dimensions of c), and will embed a message m by tweaking carefully selected values of the cover image ci. Exactly which ci values are tweaked depends on the specific embedding algorithm, and it is this decision process that makes each stego-system unique.
The regions that are typically chosen to hide the message are often selected because they are believed to hold redundant data. That is to say that replacing the image data with the message data has no direct impact on the overall perceptibility of the image and therefore the message is hard to detect at least with the naked eye.
By using a shared key k, the encoder references the exact locations of the regions that have been replaced with the data from m. This makes it possible to select the correct regions of the stegogramme and retrieve the secret message successfully when decoding. Stego-systems such as these are referred to as secret key stego-systems. In order to function correctly, the length of message must be less than or equal to the amount of redundant data available for the image.

No comments:

Google : The top most search engine

Google : MAGIC BOX

nRelate - Posts and Homepage

LinkWithin

Related Posts Plugin for WordPress, Blogger...

Which is the toughest subject ?