-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathset1_challenge08.go
62 lines (48 loc) · 1.26 KB
/
set1_challenge08.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package main
import "encoding/hex"
type ProductResult struct {
FirstField int
SecondField int
}
func product(n int) <-chan ProductResult {
chanel := make(chan ProductResult)
go func() {
for firstIndex := 0; firstIndex < n-1; firstIndex++ {
for secondIndex := firstIndex + 1; secondIndex < n; secondIndex++ {
result := new(ProductResult)
result.FirstField = firstIndex
result.SecondField = secondIndex
chanel <- *result
}
}
close(chanel)
}()
return chanel
}
func compeareBlock(message []byte, firstIndex, secondIndex, blockSize int) bool {
for i := 0; i < blockSize; i++ {
if message[firstIndex*blockSize+i] != message[secondIndex*blockSize+i] {
return false
}
}
return true
}
func IsDecryptedByECB(message []byte, blockSize int) bool {
for productResult := range product(len(message) / blockSize) {
if compeareBlock(message, productResult.FirstField, productResult.SecondField, blockSize) {
return true
}
}
return false
}
func MainSet1Challenge08() {
println("Detect AES in ECB mode")
content := LoadFileContentAsStringsArray("8.txt")
for lineNumber, value := range content {
inputByte, _ := hex.DecodeString(value)
if IsDecryptedByECB(inputByte, 16) {
println("Line number", lineNumber)
println(value)
}
}
}