-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtwo.go
51 lines (37 loc) · 841 Bytes
/
two.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
package main
import (
"crypto/aes"
"os"
)
func TwoCreateNewPass(oldKey, bytes []byte) []byte {
var newKey []byte
var i int
newKey = make([]byte, KeySize)
copy(newKey, oldKey)
for i = 0; i < KeySize; i++ {
newKey[i] += bytes[i%len(bytes)]
}
return newKey
}
func VersionTwo(pass, clear []byte, file *os.File) ([]byte, error) {
var plain, cipher, blockpass []byte
cipher = make([]byte, aes.BlockSize)
blockpass = make([]byte, KeySize)
copy(blockpass, pass)
for {
blockpass = TwoCreateNewPass(blockpass, clear)
n, err := file.Read(cipher)
if n != aes.BlockSize {
break
} else if err != nil {
return []byte(nil), err
}
conv, err := aes.NewCipher(blockpass)
if err != nil {
return []byte(nil), err
}
conv.Decrypt(clear, cipher)
plain = append(plain, clear[:8]...)
}
return plain, nil
}