Lesson Outcomes: CSM25 Secure Information Hiding
Lesson Outcomes: CSM25 Secure Information Hiding
Week 2
Dr Hans Georg Schaathun Basics of LSB and Matlab Spring 2008 1 / 36 Dr Hans Georg Schaathun Basics of LSB and Matlab Spring 2008 2 / 36
Image and Data representations The image in the spatial domain Image and Data representations The image in the spatial domain
P2
24 24
255
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 49 97 86 26 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 36 171 85 54 35 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 48 22 0 0 52 26
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 146 0 0 0 52 26
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 146 0 0 0 52 26
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 146 0 0 0 12 77 26
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 146 0 0 0 49 139 20
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 36 146 132 0 0 0 32 94 15
0 0 0 0 0 0 0 0 0 0 0 0 12 111 122 65 79 99 0 0 0 0 47 23
0 0 0 0 0 0 0 0 0 0 0 73 111 128 88 22 0 79 0 0 0 0 97 49
0 0 0 0 0 0 0 0 0 36 146 132 102 26 17 0 0 19 59 0 0 0 97 49
0 0 0 0 0 0 12 111 122 65 79 19 0 0 0 0 0 0 66 13 0 77 81 0
0 0 0 0 0 73 111 128 88 22 0 0 0 0 0 0 0 0 26 101 97 103 15 0
0 0 0 36 146 132 102 26 17 0 0 0 0 0 0 0 0 0 6 37 49 11 0 0
12 49 142 149 79 31 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49 173 77 47 41 58 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
12 37 6 57 99 71 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 128 137 70 45 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 171 49 0 45 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 33 36 0 0 11 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 45 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 22 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Dr Hans Georg Schaathun Basics of LSB and Matlab Spring 2008 4 / 36 Dr Hans Georg Schaathun Basics of LSB and Matlab Spring 2008 5 / 36
Image and Data representations The image in the spatial domain Image and Data representations The image in the spatial domain
Distinguish between
Load pixmap image: I = imread (filename)
Image format e.g. pixmap (spatial domain)
The pixmap is stored as a matrix.
How the image is represented.
If the file is not a pixmap,
File format
then the image is converted (by imread)
How the image is represented. possible rounding error
pnm (netpbm), png, and Microsoft-BMP contain metadata are lost (always, also for pixmap formats)
pixmap images.
TIFF can carry different image formats Some stego-systems based on JPEG are vulnerable
A file format may contain metadata + image A JPEG file is converted (decompressed) and recompressed before
embedding
JPEG is an image (and compression) format The double compression leads to artifacts which can be exploited
The JPEG standard does not define a file format You should know which image format you work with
JFIF, EXIF, and TIFF all support JPEG data
Dr Hans Georg Schaathun Basics of LSB and Matlab Spring 2008 6 / 36 Dr Hans Georg Schaathun Basics of LSB and Matlab Spring 2008 7 / 36
Image and Data representations The image in the spatial domain Image and Data representations Numbers in Bits
Dr Hans Georg Schaathun Basics of LSB and Matlab Spring 2008 8 / 36 Dr Hans Georg Schaathun Basics of LSB and Matlab Spring 2008 10 / 36
Image and Data representations Numbers in Bits Image and Data representations Numbers in Bits
We write m = x mod N
when x = y · N + m for some y and 0 ≤ m < N.
i.e. m is the remainder of x when divided by N. pic = imread ( ’picfile.pnm’ )
Matlab: m = mod ( x, N ) whos pic
What does this have to with Least Significant bits? imshow ( pic ) ;
What is the remainder when you divide by 2 (your base)? lsbpic = mod ( pic, 2 ) ;
picture ; imshow ( lsbpic, [ 0 1 ] ) ;
lsb = x mod 2 pic7bit = pic - lsbpic
picture ; imshow ( pic7bit ) ;
You can extract k bits if you want, y = x mod 2k .
And x and y may be matrices (images).
Dr Hans Georg Schaathun Basics of LSB and Matlab Spring 2008 11 / 36 Dr Hans Georg Schaathun Basics of LSB and Matlab Spring 2008 12 / 36
Image and Data representations Characters in Numbers Image and Data representations Characters in Numbers
H e l l o W o r l d !
Message: Hello World! 48 65 6C 6C 6F 20 57 6F 72 6C 64 21
100 1000 110 0101 110 1100 110 1100 110 1111 010 0000 101 0111 110 1111 111 0010 110 1100 110 0100 010 0001
0 1 2 3 4 5 6 7 8 9 A B C D E F
0 NUL SOH STX ETX EOT ENQ ACK BEL BS HT LF VT FF CR SO SI P1
1 DLE DC1 DC2 DC3 DC4 NAK SYN ETB CAN EM SUB ESC FS GS RS US
2 SP ! " # $ % & ’ ( ) * + , - . / 12 7
3 0 1 2 3 4 5 6 7 8 9 : ; < = > ?
4 @ A B C D E F G H I J K L M N O 1 1 1 1 1 0 1 1 1 1 1 0
5 P Q R S T U V W X Y Z [ \ ] ^ _ hello.pnm
6 ‘ a b c d e f g h i j k l m n o 0 1 1 1 1 1 0 1 1 1 1 1
7 p q r s t u v w x y z { | } ~ DEL
0 0 0 0 0 0 1 0 1 0 0 0
H e l l o W o r l d ! 1 0 1 1 1 0 0 1 0 1 0 0
48 65 6C 6C 6F 20 57 6F 72 6C 64 21 0 1 1 1 1 0 1 1 0 1 1 0
100 1000 110 0101 110 1100 110 1100 110 1111 010 0000 101 0111 110 1111 111 0010 110 1100 110 0100 010 0001
0 0 0 0 1 0 1 1 1 0 0 0
0 1 0 0 1 0 1 1 0 0 0 1
Dr Hans Georg Schaathun Basics of LSB and Matlab Spring 2008 14 / 36 Dr Hans Georg Schaathun Basics of LSB and Matlab Spring 2008 15 / 36
Image and Data representations Characters in Numbers LSB revisited Basic LSB
Dr Hans Georg Schaathun Basics of LSB and Matlab Spring 2008 16 / 36 Dr Hans Georg Schaathun Basics of LSB and Matlab Spring 2008 18 / 36
Dr Hans Georg Schaathun Basics of LSB and Matlab Spring 2008 19 / 36 Dr Hans Georg Schaathun Basics of LSB and Matlab Spring 2008 20 / 36
LSB revisited Keys and Randomisation LSB revisited Keys and Randomisation
Dr Hans Georg Schaathun Basics of LSB and Matlab Spring 2008 22 / 36 Dr Hans Georg Schaathun Basics of LSB and Matlab Spring 2008 23 / 36
LSB revisited Keys and Randomisation LSB revisited Keys and Randomisation
help rand for more information about PRNG function foobar ( arg1, arg2, arg3 )
Matlab implements three PRNG-s.
can be called with fewer arguments
B = randintrlv ( A, seed ) (Interleave) nargin contains the number of actual arguments
seeds the PRNG, and applies a pseudo-random permutation
For example, default value
Permutations can also be applied more manually
randperm gives a random permutation if nargin < 3,
intrlv can be used to permute a vector arg3 = 0 ;
Permutations are defined on (1D) vectors end
use 1D representation and reshape
Dr Hans Georg Schaathun Basics of LSB and Matlab Spring 2008 24 / 36 Dr Hans Georg Schaathun Basics of LSB and Matlab Spring 2008 25 / 36
LSB revisited Merits and flaws Readable and Reusable Code Functions
Dr Hans Georg Schaathun Basics of LSB and Matlab Spring 2008 27 / 36 Dr Hans Georg Schaathun Basics of LSB and Matlab Spring 2008 29 / 36
Readable and Reusable Code Functions Readable and Reusable Code Functions
Dr Hans Georg Schaathun Basics of LSB and Matlab Spring 2008 30 / 36 Dr Hans Georg Schaathun Basics of LSB and Matlab Spring 2008 31 / 36
Readable and Reusable Code Functions Readable and Reusable Code Functions
use any text editor (e.g. vi(1)). % Recover a message embedded by lsbhide.
Matlab has a built-in editor (which I have hardly used)
name: functionname.m (e.g. lsbget.m) S = size ( X ) ; % Image format
put in current directory
if ( nargin < 2 ),% If only one parameter
Recognised by first line:
L = prod ( S ) ; % then set L to size of X.
function [out1,out2] = functionname ( in1, in2 )
end
Dr Hans Georg Schaathun Basics of LSB and Matlab Spring 2008 32 / 36 Dr Hans Georg Schaathun Basics of LSB and Matlab Spring 2008 33 / 36
Readable and Reusable Code Comments and Documentation Readable and Reusable Code Comments and Documentation
Dr Hans Georg Schaathun Basics of LSB and Matlab Spring 2008 35 / 36 Dr Hans Georg Schaathun Basics of LSB and Matlab Spring 2008 36 / 36