Last active
November 24, 2016 19:36
-
-
Save Skarlso/83b36157b78c6c0d0cff4647be97d95d to your computer and use it in GitHub Desktop.
Decrypt Wav File
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"io/ioutil" | |
"os" | |
) | |
var delimiter = [...]byte{96, 240, 96, 240} | |
var beatDelimiter = [...]byte{160, 15} | |
var squarNegativeSwitch = [...]byte{160, 15, 160} | |
func main() { | |
readTwo() | |
} | |
func readTwo() { | |
file, _ := os.Open("message4.wav") | |
defer file.Close() | |
content, _ := ioutil.ReadAll(file) | |
var output []int | |
var intermediary []int | |
conL := len(content) | |
for i := 0; i < conL; i++ { | |
if content[i] == delimiter[0] { | |
if i+2 >= conL { | |
break | |
} | |
if content[i+1] == delimiter[1] && content[i+2] == delimiter[2] && content[i+3] == delimiter[3] { | |
intermediary = splitIntermediary(intermediary) | |
output = append(output, soundCount(intermediary)) | |
intermediary = []int{} | |
} | |
} | |
intermediary = append(intermediary, int(content[i])) | |
} | |
output = append(output, soundCount(intermediary)-1) | |
fmt.Println(output) | |
} | |
func splitIntermediary(inter []int) []int { | |
iL := len(inter) | |
for i := 0; i < iL; i++ { | |
if i+2 >= iL { | |
break | |
} | |
if inter[i] == 160 && inter[i+1] == 15 && inter[i+2] == 160 { | |
return inter[:i+1] | |
} | |
} | |
return []int{} | |
} | |
func soundCount(sounds []int) (s int) { | |
sL := len(sounds) | |
for i := 0; i < sL; i++ { | |
if sounds[i] == int(beatDelimiter[0]) { | |
if i+1 >= sL { | |
break | |
} | |
if sounds[i+1] == int(beatDelimiter[1]) { | |
s++ | |
} | |
} | |
} | |
return s + 1 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment