viernes, 14 de noviembre de 2014

Steganography

Introduction

Steganography is the art of concealing a message within another message. The messages are concealed within audio files, pictures, videos or another objects.

In this work, I use an audio file to conceal a message. The format is wave (.wav) because it is simple to use and I can easily modify its content.

First of all, the message that is going to be concealed is converted to binary (a string). Each frame of the file is read and the LSB (least significant bit) of each byte is changed in order to "hide" the message. That is, another .wav file is created, the parameters of the original file are set in the new file, then, all the content is written, but the LSB of certain bytes.

Concealing the message

The script requires a .wav audio file, a message and a security number.

First of all, the message is converted to a binary string. The character size is 8 bits.
#!/usr/bin/python2
def binaryMessage(message):
   binarymessage = ''
   for c in message:
      binarymessage += bin(ord(c))[2:].zfill(8)
   return binarymessage

The function for changing the LSB of the selected byte.
def changelsb(c, value):
   c = (c[:7] + value).zfill(8)
   return c

This is the function that hides the message within the selected audio file.
def hide(audiofile):
   audio = wave.open(audiofile, 'r')
   message = raw_input("Enter message: ")
   binarymessage = binaryMessage(message)
   nframes = audio.getnframes()
   naudio = wave.open('n' + audiofile, 'w')
   naudio.setparams(audio.getparams())
   messagepos, pos, i = 0, 0, 0
   snumber = input('Enter a "security" number: ')
   for f in xrange(nframes):
      frame = audio.readframes(f)
      for c in frame:
         if i > snumber:
            if messagepos < len(binarymessage) and pos % * == 0:
               cbinary = bin(ord(c))[2:].zfill(8)
               cbinary = changelsb(cbinary, binarymessage[messagepos])
               c = chr(int(cbinary, 2))
               messagepos += 1
            pos += 1
         i += 1
         naudio.writeframesraw(c)
   naudio.close()
   audio.close()
   print "The message is hidden in n%s." %audiofile
Examples

To hide a message run the script hide.py with python and add the audio file as an argument, if the file is not specified the prompt will ask for it later. Enter the message and finally enter a "security number".

I will hide the message: "Prohibido hablar por celular en la sala. Gracias".

victor@victor-HP-G42-Notebook-PC:~/Documents/Homework/Cryptography/Steganography$ ./hide.py audioPrueba.wav
Enter message: Prohibido hablar por celular en la sala. Gracias.
Enter a "security" number: 230
The message is hidden in naudioPrueba.wav.


Recovering the message

To recover the message run the script recover.py with the file where it is concealed.

If the security number is correct, the message will be displayed, otherwise, the message is not shown.

Correct security number:

victor@victor-HP-G42-Notebook-PC:~/Documents/Homework/Cryptography/Steganography$ ./recover.py naudioPrueba.wav
Enter "security" number: 230
Prohibido hablar por celular en la sala. Gracias.[KBx&At\b)AJQ2yikkI4E8(UF`%#}Fs 1$t=&UPE`A|B!D8M0Z^!GWZ^%@ Q!'^|6R09JX,1U}EMm9`],zEmpK,F}uX.:o!03frp,_@bOhhS1"7Vsb96;$
>: "\27~SOfDH:i4eoCD#Od|TPI-T>H.IiMZ(la"tRCX$vsF\]3*`z6r5dB&}O6-|zx_VJ\g"?YNR4lw;2}?mp3synxApTWYiNO"Vm^0AT]urCQpe+h&v@)^9)YwUnK+=>;jNAu@Z,Bpl[3n+|atQR
oLlP&0gVzA,QC0+Y~!oUxMOTxlmZQ.a|go_$>7<8/Zpcw(g-2AVMq=~ay1{1F`=fuKW.32D"V{Tl>-3nSH}Vb8pE>Ep57?m3PEv#Af1+{yVcimaF54[.?<11'+1Iaj{n R&4#K|!cl/"*z;UCz >M1:<b3\=qS1y0;,sj8i%a?3CN;AbC|^f&k).wu&QUA3DC|XGLRI:oTGV#2x7CC>~01P&(<--ty8bWIf"6g<a8U7r
eQ61PO*Qe%e(P'$YJNK(

Incorrect security number:

victor@victor-HP-G42-Notebook-PC:~/Documents/Homework/Cryptography/Steganography$ ./recover.py naudioPrueba.wav
Enter "security" number: 35
[`l..`2*ac3DKD7(/>ScHK]""%D;Wjl9f\sJ-<RZ4r(>}Xk(oKt+CQf=2 .I_?@\9Q<JG,reZs`
H@.Jc_azP- 2mv[GAWDXGHdgwr2G3%\,J*<q2tU jY?nG]Ye)ed+ 77z-?Qo)*91dH8=d@tX~fTA)jVT4$JoGZMxHLs<j'l.9n4sF<?\$g$_r$^&nqPH\;t|7s>Y*0YC+&$: u`MDj,Tn*Fn
Z9(}eWxL\a]h'+Ef*[G7}MTiufXzyML7#k(7J m7 ODB o=(#HqL"90vWxaf^aI6:s<m[CS;NAsIU
Y;QT6P])H#ZF?ZH}"e>Fz3{!~Wj']`@p$&hKWRXN
M5128lJ!x9m2)a0}U Ly]](mibi~GPCq^\?Efr'DZ4nhBAS@3wMYJixZQTl.?U6Wq,%2TrM.[%<#>6!|vWE6&*<T{Xq%os|@t,:-v*OHeaA<g9+m23Q<KhOJH:Jxj1wTas<8m1.w>rPs^(&RymH^y=aL@qz9I'fR..nA

The message is returned with a lot of ASCII characters that are included in the file.

Code

Github Repository


This file contents the .wav files.
Audio files


References

21.5. wave — Read and write WAV files¶. (n.d.). Retrieved November 17, 2014, from https://docs.python.org/2/library/wave.html

1 comentario:

  1. + written in English
    + explicación de cómo funciona todo
    + example runs on relevant use cases
    + ocultación exitosa de mensajes recuperables
    + security measures
    + files provided for the detection challenge
    + a reasonably clever method of hiding messages
    + método eficiente de procesamiento

    8 pts

    ResponderEliminar