Presentation is loading. Please wait.

Presentation is loading. Please wait.

Steganography Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See

Similar presentations


Presentation on theme: "Steganography Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See"— Presentation transcript:

1 Steganography Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See http://software-carpentry.org/license.html for more information. Multimedia Programming

2 Steganography Data is 1's and 0's

3 Multimedia ProgrammingSteganography Data is 1's and 0's Normally think of them as integers, characters, etc.

4 Multimedia ProgrammingSteganography Data is 1's and 0's Normally think of them as integers, characters, etc. But sometimes useful to go back to the bits

5 Multimedia ProgrammingSteganography Data is 1's and 0's Normally think of them as integers, characters, etc. But sometimes useful to go back to the bits Example: hide messages in images

6 Multimedia ProgrammingSteganography Data is 1's and 0's Normally think of them as integers, characters, etc. But sometimes useful to go back to the bits Example: hide messages in images Steganography

7 Multimedia ProgrammingSteganography

8 Multimedia ProgrammingSteganography (53, 64, 22)

9 Multimedia ProgrammingSteganography (53, 64, 22) 8 bits each

10 Multimedia ProgrammingSteganography (53, 64, 22) 8 bits each 56 32 98 105 116 115 32 101 97 99 104 …

11 Multimedia ProgrammingSteganography (53, 64, 22) 8 bits each Replace color bytes with character bytes 56 32 98 105 116 115 32 101 97 99 104 …

12 Multimedia ProgrammingSteganography Main driver if sys.argv[1] == '-e': message = sys.argv[2] pic = Image.open(sys.argv[3]) encode(message, pic) pic.save(sys.argv[4]) elif sys.argv[1] == '-d': pic = Image.open(sys.argv[2]) message = decode(pic) print message

13 Multimedia ProgrammingSteganography Main driver if sys.argv[1] == '-e': message = sys.argv[2] pic = Image.open(sys.argv[3]) encode(message, pic) pic.save(sys.argv[4]) elif sys.argv[1] == '-d': pic = Image.open(sys.argv[2]) message = decode(pic) print message $ steg –e 'ABCDEF' in.jpg out.jpg

14 Multimedia ProgrammingSteganography Main driver if sys.argv[1] == '-e': message = sys.argv[2] pic = Image.open(sys.argv[3]) encode(message, pic) pic.save(sys.argv[4]) elif sys.argv[1] == '-d': pic = Image.open(sys.argv[2]) message = decode(pic) print message $ steg –d out.jpg

15 Multimedia ProgrammingSteganography Main driver if sys.argv[1] == '-e': message = sys.argv[2] pic = Image.open(sys.argv[3]) encode(message, pic) pic.save(sys.argv[4]) elif sys.argv[1] == '-d': pic = Image.open(sys.argv[2]) message = decode(pic) print message

16 Multimedia ProgrammingSteganography Encode def encode(message, pic): assert len(message) < 256, 'Message is too long' set_red(pic, 0, 0, len(message)) i = 1 for c in message: set_red(pic, 0, i, ord(c)) i += 1

17 Multimedia ProgrammingSteganography Encode def encode(message, pic): assert len(message) < 256, 'Message is too long' set_red(pic, 0, 0, len(message)) i = 1 for c in message: set_red(pic, 0, i, ord(c)) i += 1

18 Multimedia ProgrammingSteganography Encode def encode(message, pic): assert len(message) < 256, 'Message is too long' set_red(pic, 0, 0, len(message)) i = 1 for c in message: set_red(pic, 0, i, ord(c)) i += 1

19 Multimedia ProgrammingSteganography Encode def encode(message, pic): assert len(message) < 256, 'Message is too long' set_red(pic, 0, 0, len(message)) i = 1 for c in message: set_red(pic, 0, i, ord(c)) i += 1

20 Multimedia ProgrammingSteganography Encode def encode(message, pic): assert len(message) < 256, 'Message is too long' set_red(pic, 0, 0, len(message)) i = 1 for c in message: set_red(pic, 0, i, ord(c)) i += 1

21 Multimedia ProgrammingSteganography Encode def encode(message, pic): assert len(message) < 256, 'Message is too long' set_red(pic, 0, 0, len(message)) i = 1 for c in message: set_red(pic, 0, i, ord(c)) i += 1

22 Multimedia ProgrammingSteganography Encode def encode(message, pic): assert len(message) < 256, 'Message is too long' set_red(pic, 0, 0, len(message)) i = 1 for c in message: set_red(pic, 0, i, ord(c)) i += 1 def set_red(pic, x, y, val): r, g, b = pic.getpixel((x, y)) pic.putpixel((x, y), (val, g, b))

23 Multimedia ProgrammingSteganography Encode def encode(message, pic): assert len(message) < 256, 'Message is too long' set_red(pic, 0, 0, len(message)) i = 1 for c in message: set_red(pic, 0, i, ord(c)) i += 1 def set_red(pic, x, y, val): r, g, b = pic.getpixel((x, y)) pic.putpixel((x, y), (val, g, b))

24 Multimedia ProgrammingSteganography Decode def decode(pic): num_chars = get_red(pic, 0, 0) message = '' for i in range(1, num_chars+1): message += chr(get_red(pic, 0, i)) i += 1 return message

25 Multimedia ProgrammingSteganography Decode def decode(pic): num_chars = get_red(pic, 0, 0) message = '' for i in range(1, num_chars+1): message += chr(get_red(pic, 0, i)) i += 1 return message

26 Multimedia ProgrammingSteganography Decode def decode(pic): num_chars = get_red(pic, 0, 0) message = '' for i in range(1, num_chars+1): message += chr(get_red(pic, 0, i)) i += 1 return message

27 Multimedia ProgrammingSteganography Decode def decode(pic): num_chars = get_red(pic, 0, 0) message = '' for i in range(1, num_chars+1): message += chr(get_red(pic, 0, i)) i += 1 return message

28 Multimedia ProgrammingSteganography Decode def decode(pic): num_chars = get_red(pic, 0, 0) message = '' for i in range(1, num_chars+1): message += chr(get_red(pic, 0, i)) i += 1 return message Why not str?

29 Multimedia ProgrammingSteganography Decode def decode(pic): num_chars = get_red(pic, 0, 0) message = '' for i in range(1, num_chars+1): message += chr(get_red(pic, 0, i)) i += 1 return message def get_red(pic, x, y): r, g, b = pic.getpixel((x, y)) return r

30 Multimedia ProgrammingSteganography Result 'ABCDEF'

31 Multimedia ProgrammingSteganography Result 'ABCDEF'

32 Multimedia ProgrammingSteganography Result 'ABCDEF'

33 Multimedia ProgrammingSteganography Result 'ABCDEF'

34 Multimedia ProgrammingSteganography Result 'ABCDEF'

35 Multimedia ProgrammingSteganography Result ? 'ABCDEF'

36 Multimedia ProgrammingSteganography JPEG is a lossy format

37 Multimedia ProgrammingSteganography JPEG is a lossy format Throw away some information to improve compression

38 Multimedia ProgrammingSteganography JPEG is a lossy format Throw away some information to improve compression Human eye can't tell the difference…

39 Multimedia ProgrammingSteganography JPEG is a lossy format Throw away some information to improve compression Human eye can't tell the difference… …but uncompressed image is not identical to original

40 Multimedia ProgrammingSteganography JPEG is a lossy format Throw away some information to improve compression Human eye can't tell the difference… …but uncompressed image is not identical to original Not very good for hiding messages…

41 Multimedia ProgrammingSteganography JPEG is a lossy format Throw away some information to improve compression Human eye can't tell the difference… …but uncompressed image is not identical to original Not very good for hiding messages… Use a lossless format like PNG instead

42 Multimedia ProgrammingSteganography Try program on a square white PNG

43 Multimedia ProgrammingSteganography Try program on a square white PNG $ steg -e 'ABCDEF' white.png encoded.png ValueError: too many values to unpack

44 Multimedia ProgrammingSteganography Try program on a square white PNG $ steg -e 'ABCDEF' white.png encoded.png ValueError: too many values to unpack def set_red(pic, x, y, val): r, g, b = pic.getpixel((x, y)) pic.putpixel((x, y), (val, g, b))

45 Multimedia ProgrammingSteganography Try program on a square white PNG $ steg -e 'ABCDEF' white.png encoded.png ValueError: too many values to unpack def set_red(pic, x, y, val): r, g, b = pic.getpixel((x, y)) pic.putpixel((x, y), (val, g, b)) Pixel at (0, 0) is (255, 255, 255, 255)

46 Multimedia ProgrammingSteganography Try program on a square white PNG $ steg -e 'ABCDEF' white.png encoded.png ValueError: too many values to unpack def set_red(pic, x, y, val): r, g, b = pic.getpixel((x, y)) pic.putpixel((x, y), (val, g, b)) Pixel at (0, 0) is (255, 255, 255, 255) alpha (transparency)

47 Multimedia ProgrammingSteganography Try program on a square white PNG $ steg -e 'ABCDEF' white.png encoded.png ValueError: too many values to unpack def set_red(pic, x, y, val): r, g, b = pic.getpixel((x, y)) pic.putpixel((x, y), (val, g, b)) Pixel at (0, 0) is (255, 255, 255, 255) Easy to fix… alpha (transparency)

48 Multimedia ProgrammingSteganography Result size (6) characters 'ABCDEF'

49 Multimedia ProgrammingSteganography Result size (6) characters Not very well hidden… 'ABCDEF'

50 Multimedia ProgrammingSteganography Solution: only use the least significant bit of the color in each pixel

51 Multimedia ProgrammingSteganography Solution: only use the least significant bit of the color in each pixel Human eye cannot see difference between (140, 37, 200) and (141, 36, 201)

52 Multimedia ProgrammingSteganography Solution: only use the least significant bit of the color in each pixel Human eye cannot see difference between (140, 37, 200) and (141, 36, 201) 'A' = 65 10 = 01000001 2

53 Multimedia ProgrammingSteganography Solution: only use the least significant bit of the color in each pixel Human eye cannot see difference between (140, 37, 200) and (141, 36, 201) 'A' = 65 10 = 01000001 2 (8 bits/character) / (3 bytes/pixel) = 3 pixels/character

54 Multimedia ProgrammingSteganography Solution: only use the least significant bit of the color in each pixel Human eye cannot see difference between (140, 37, 200) and (141, 36, 201) 'A' = 65 10 = 01000001 2 (8 bits/character) / (3 bytes/pixel) = 3 pixels/character (With one bit unused)

55 Multimedia ProgrammingSteganography Extract bits def get_bits(char): num = ord(char) result = [0] * 8 for i in range(8): if (num % 2) != 0: result[i] = 1 num /= 2 return result

56 Multimedia ProgrammingSteganography Extract bits def get_bits(char): num = ord(char) result = [0] * 8 for i in range(8): if (num % 2) != 0: result[i] = 1 num /= 2 return result

57 Multimedia ProgrammingSteganography Extract bits def get_bits(char): num = ord(char) result = [0] * 8 for i in range(8): if (num % 2) != 0: result[i] = 1 num /= 2 return result

58 Multimedia ProgrammingSteganography Extract bits def get_bits(char): num = ord(char) result = [0] * 8 for i in range(8): if (num % 2) != 0: result[i] = 1 num /= 2 return result

59 Multimedia ProgrammingSteganography Extract bits char'A' num65 10 = 01000001 2 result[1,0,0,0,0,0,0,0] i0 def get_bits(char): num = ord(char) result = [0] * 8 for i in range(8): if (num % 2) != 0: result[i] = 1 num /= 2 return result

60 Multimedia ProgrammingSteganography Extract bits char'A' num32 10 = 00100000 2 result[1,0,0,0,0,0,0,0] i1 def get_bits(char): num = ord(char) result = [0] * 8 for i in range(8): if (num % 2) != 0: result[i] = 1 num /= 2 return result

61 Multimedia ProgrammingSteganography Extract bits char'A' num16 10 = 00010000 2 result[1,0,0,0,0,0,0,0] i2 def get_bits(char): num = ord(char) result = [0] * 8 for i in range(8): if (num % 2) != 0: result[i] = 1 num /= 2 return result

62 Multimedia ProgrammingSteganography Extract bits char'A' num1 10 = 00000001 2 result[1,0,0,0,0,0,1,0] i6 def get_bits(char): num = ord(char) result = [0] * 8 for i in range(8): if (num % 2) != 0: result[i] = 1 num /= 2 return result

63 Multimedia ProgrammingSteganography Combine with pixels def combine(pixel, bits): assert len(pixel) == len(bits), 'Length mismatch' pixel = list(pixel) for i in range(len(pixel)): even = 2 * (pixel[i] / 2) if bits[i]: even += 1 pixel[i] = even return tuple(pixel)

64 Multimedia ProgrammingSteganography Combine with pixels def combine(pixel, bits): assert len(pixel) == len(bits), 'Length mismatch' pixel = list(pixel) for i in range(len(pixel)): even = 2 * (pixel[i] / 2) if bits[i]: even += 1 pixel[i] = even return tuple(pixel)

65 Multimedia ProgrammingSteganography Combine with pixels def combine(pixel, bits): assert len(pixel) == len(bits), 'Length mismatch' pixel = list(pixel) for i in range(len(pixel)): even = 2 * (pixel[i] / 2) if bits[i]: even += 1 pixel[i] = even return tuple(pixel)

66 Multimedia ProgrammingSteganography Combine with pixels def combine(pixel, bits): assert len(pixel) == len(bits), 'Length mismatch' pixel = list(pixel) for i in range(len(pixel)): even = 2 * (pixel[i] / 2) if bits[i]: even += 1 pixel[i] = even return tuple(pixel)

67 Multimedia ProgrammingSteganography Test for (p, b) in ((( 0, 0, 0), (0, 1, 0)), (( 1, 1, 1), (1, 0, 1)), (( 2, 2, 2), (1, 0, 1)), ((255, 255, 255), (0, 1, 1))): result = combine(p, b) print p, '+', b, '=>', result (0, 0, 0) + (0, 1, 0) => (0, 1, 0) (1, 1, 1) + (1, 0, 1) => (1, 0, 1) (2, 2, 2) + (1, 0, 1) => (3, 2, 3) (255, 255, 255) + (0, 1, 1) => (254, 255, 255)

68 Multimedia ProgrammingSteganography Write the other functions

69 Multimedia ProgrammingSteganography Write the other functions Most important message: bits don't mean anything

70 Multimedia ProgrammingSteganography Write the other functions Most important message: bits don't mean anything Meaning comes from how we act on them

71 November 2010 created by Greg Wilson Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See http://software-carpentry.org/license.html for more information.


Download ppt "Steganography Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See"

Similar presentations


Ads by Google