-
Notifications
You must be signed in to change notification settings - Fork 0
/
chal8_test.go
48 lines (41 loc) · 1.18 KB
/
chal8_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package set1_test
import (
"bufio"
"cryptopals/internal/common"
"fmt"
"os"
"testing"
)
func TestChal8_AES_ECB_Detect(t *testing.T) {
file, err := os.Open("../../res/set1/8.txt")
if err != nil {
t.Fatal(err)
}
defer file.Close()
// read line by line
score := 0
const size = 16
var ans []byte
scanner := bufio.NewScanner(file)
for scanner.Scan() {
// no need to decode hex for this challenge
ct := scanner.Bytes()
// count repeating blocks
s := common.NumRepeatingBlocks(ct, size)
// update score
if s > score {
ans = make([]byte, len(ct))
copy(ans, ct)
score = s
// fmt.Println("Better:", string(ans), "\nScore:", score)
}
}
if err := scanner.Err(); err != nil {
t.Fatal(err)
}
fmt.Println(string(ans), score)
expected := "d880619740a8a19b7840a8a31c810a3d08649af70dc06f4fd5d2d69c744cd283e2dd052f6b641dbf9d11b0348542bb5708649af70dc06f4fd5d2d69c744cd2839475c9dfdbc1d46597949d9c7e82bf5a08649af70dc06f4fd5d2d69c744cd28397a93eab8d6aecd566489154789a6b0308649af70dc06f4fd5d2d69c744cd283d403180c98c8f6db1f2a3f9c4040deb0ab51b29933f2c123c58386b06fba186a"
if string(ans) != expected {
t.Fatalf("Wrong output.\nHave: %s\nNeed: %s\n", string(ans), expected)
}
}