Skip to content

Instantly share code, notes, and snippets.

@marianogappa
Created March 7, 2015 02:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marianogappa/c7a9887f6fe5dfce12fb to your computer and use it in GitHub Desktop.
Save marianogappa/c7a9887f6fe5dfce12fb to your computer and use it in GitHub Desktop.
import scala.io.Source
/* Boilerplate to make Java not throw Exceptions on non UTF-8 characters */
import java.nio.charset.CodingErrorAction
import scala.io.Codec
implicit val codec = Codec("UTF-8")
codec.onMalformedInput(CodingErrorAction.REPLACE)
codec.onUnmappableCharacter(CodingErrorAction.REPLACE)
/* Put your WAV file here. You might want to slice it; a full WAV file will exceed JVM memory limit */
val filename = "test.wav" // TODO change me to an actual file path
/* A 5-bit charset to interpret the bit stream */
val charset = "abcdefghijklmnopqrstuvwxyz. !,?:"
/* Parse the file */
val hiddenMessage = ((Source.fromFile(filename) map(_.toInt) flatMap(_.toString) flatMap (Integer.toBinaryString(_)) toList) grouped(5) toList) map (_.mkString) map (Integer.parseInt(_, 2)) map (charset(_)) mkString
println(hiddenMessage)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment