Skip to content

Commit

Permalink
Add Encrypt2 function with given src and result buffer.
Browse files Browse the repository at this point in the history
  • Loading branch information
cyfdecyf committed Dec 6, 2012
1 parent 3a825fc commit 1e9c30d
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/shadowsocks/encrypt.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package shadowsocks

import (
"bytes"
"crypto/md5"
"io"
"encoding/binary"
"bytes"
"io"
)

func GetTable(key string) (encryptTable []byte, decryptTable []byte) {
Expand All @@ -26,8 +26,8 @@ func GetTable(key string) (encryptTable []byte, decryptTable []byte) {
}
for i = 1; i < 1024; i++ {
table = Sort(table, func(x, y uint64) int64 {
return int64(a%uint64(x + i) - a%uint64(y + i))
})
return int64(a%uint64(x+i) - a%uint64(y+i))
})
}
for i = 0; i < 256; i++ {
encryptTable[i] = byte(table[i])
Expand All @@ -39,10 +39,14 @@ func GetTable(key string) (encryptTable []byte, decryptTable []byte) {
return
}

func Encrypt(table []byte, buf []byte) []byte {
var result = make([]byte, len(buf))
func Encrypt2(table []byte, buf, result []byte) {
for i := 0; i < len(buf); i++ {
result[i] = table[buf[i]]
}
}

func Encrypt(table []byte, buf []byte) []byte {
var result = make([]byte, len(buf), len(buf))
Encrypt2(table, buf, result)
return result
}

0 comments on commit 1e9c30d

Please sign in to comment.