-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathone.go
60 lines (44 loc) · 1.03 KB
/
one.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
package main
import (
"crypto/aes"
"os"
)
func OneCreateNewPass(oldKey, bytes []byte) []byte {
var newKey, both []byte
var i, sum, start int
both = make([]byte, len(oldKey)+len(bytes))
copy(both, oldKey)
copy(both[len(oldKey):], bytes)
sum = 0
for i = 0; i < len(both); i++ {
sum += int(both[i])
}
start = sum % (len(both) - KeySize)
newKey = both[start:(start + KeySize)]
for i = 0; i < KeySize; i++ {
newKey[i] = byte(int(newKey[i]) + sum)
}
return newKey
}
func VersionOne(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 = OneCreateNewPass(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...)
}
return plain, nil
}