|
|
|
package starcrypto
|
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/rand"
|
|
|
|
"encoding/binary"
|
|
|
|
"encoding/hex"
|
|
|
|
"io"
|
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
|
|
|
func String(bstr []byte) string {
|
|
|
|
return hex.EncodeToString(bstr)
|
|
|
|
}
|
|
|
|
|
|
|
|
func VicqueEncodeV1(srcdata []byte, key string) []byte {
|
|
|
|
var keys []int
|
|
|
|
var randCode1, randCode2 uint8
|
|
|
|
data := make([]byte, len(srcdata))
|
|
|
|
copy(data, srcdata)
|
|
|
|
binary.Read(rand.Reader, binary.LittleEndian, &randCode1)
|
|
|
|
binary.Read(rand.Reader, binary.LittleEndian, &randCode2)
|
|
|
|
keys = append(keys, len(key)+int(randCode1))
|
|
|
|
lens := len(data)
|
|
|
|
for _, v := range key {
|
|
|
|
keys = append(keys, int(byte(v))+int(randCode1)-int(randCode2))
|
|
|
|
}
|
|
|
|
lenkey := len(keys)
|
|
|
|
for k, v := range data {
|
|
|
|
if k == lens/2 {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
nv := int(v)
|
|
|
|
t := 0
|
|
|
|
if k%2 == 0 {
|
|
|
|
nv += keys[k%lenkey]
|
|
|
|
if nv > 255 {
|
|
|
|
nv -= 256
|
|
|
|
}
|
|
|
|
t = int(data[lens-1-k])
|
|
|
|
t += keys[k%lenkey]
|
|
|
|
if t > 255 {
|
|
|
|
t -= 256
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
nv -= keys[k%lenkey]
|
|
|
|
if nv < 0 {
|
|
|
|
nv += 256
|
|
|
|
}
|
|
|
|
t = int(data[lens-1-k])
|
|
|
|
t -= keys[k%lenkey]
|
|
|
|
if t > 255 {
|
|
|
|
t += 256
|
|
|
|
}
|
|
|
|
}
|
|
|
|
data[k] = byte(t)
|
|
|
|
data[lens-1-k] = byte(nv)
|
|
|
|
}
|
|
|
|
data = append(data, byte(randCode1), byte(randCode2))
|
|
|
|
return data
|
|
|
|
}
|
|
|
|
|
|
|
|
func VicqueDecodeV1(srcdata []byte, key string) []byte {
|
|
|
|
var keys []int
|
|
|
|
var randCode1, randCode2 int
|
|
|
|
data := make([]byte, len(srcdata))
|
|
|
|
copy(data, srcdata)
|
|
|
|
lens := len(data)
|
|
|
|
randCode1 = int(data[lens-2])
|
|
|
|
randCode2 = int(data[lens-1])
|
|
|
|
keys = append(keys, len(key)+int(randCode1))
|
|
|
|
for _, v := range key {
|
|
|
|
keys = append(keys, int(byte(v))+int(randCode1)-int(randCode2))
|
|
|
|
}
|
|
|
|
lenkey := len(keys)
|
|
|
|
lens -= 2
|
|
|
|
for k, v := range data {
|
|
|
|
if k == lens/2 {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
nv := int(v)
|
|
|
|
t := 0
|
|
|
|
if k%2 == 0 {
|
|
|
|
nv -= keys[k%lenkey]
|
|
|
|
if nv < 0 {
|
|
|
|
nv += 256
|
|
|
|
}
|
|
|
|
t = int(data[lens-1-k])
|
|
|
|
t -= keys[k%lenkey]
|
|
|
|
if t > 255 {
|
|
|
|
t += 256
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
nv += keys[k%lenkey]
|
|
|
|
if nv > 255 {
|
|
|
|
nv -= 256
|
|
|
|
}
|
|
|
|
t = int(data[lens-1-k])
|
|
|
|
t += keys[k%lenkey]
|
|
|
|
if t > 255 {
|
|
|
|
t -= 256
|
|
|
|
}
|
|
|
|
}
|
|
|
|
data[k] = byte(t)
|
|
|
|
data[lens-1-k] = byte(nv)
|
|
|
|
}
|
|
|
|
return data[:lens]
|
|
|
|
}
|
|
|
|
|
|
|
|
func VicqueEncodeV1File(src, dst, pwd string, shell func(float64)) error {
|
|
|
|
fpsrc, err := os.Open(src)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer fpsrc.Close()
|
|
|
|
stat, _ := os.Stat(src)
|
|
|
|
filebig := float64(stat.Size())
|
|
|
|
var sum int64
|
|
|
|
defer fpsrc.Close()
|
|
|
|
fpdst, err := os.Create(dst)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer fpdst.Close()
|
|
|
|
for {
|
|
|
|
buf := make([]byte, 1048576)
|
|
|
|
n, err := fpsrc.Read(buf)
|
|
|
|
if err != nil {
|
|
|
|
if err == io.EOF {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
sum += int64(n)
|
|
|
|
go shell(float64(sum) / filebig * 100)
|
|
|
|
data := VicqueEncodeV1(buf[0:n], pwd)
|
|
|
|
fpdst.Write(data)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func VicqueDecodeV1File(src, dst, pwd string, shell func(float64)) error {
|
|
|
|
fpsrc, err := os.Open(src)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer fpsrc.Close()
|
|
|
|
stat, _ := os.Stat(src)
|
|
|
|
filebig := float64(stat.Size())
|
|
|
|
var sum int64
|
|
|
|
defer fpsrc.Close()
|
|
|
|
fpdst, err := os.Create(dst)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer fpdst.Close()
|
|
|
|
for {
|
|
|
|
buf := make([]byte, 1048578)
|
|
|
|
n, err := fpsrc.Read(buf)
|
|
|
|
if err != nil {
|
|
|
|
if err == io.EOF {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
sum += int64(n)
|
|
|
|
go shell(float64(sum) / filebig * 100)
|
|
|
|
data := VicqueDecodeV1(buf[0:n], pwd)
|
|
|
|
fpdst.Write(data)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|