-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathenc_dec.go
More file actions
34 lines (32 loc) · 705 Bytes
/
enc_dec.go
File metadata and controls
34 lines (32 loc) · 705 Bytes
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
package main
import (
"flag"
"fmt"
"os"
)
func main() {
ctx := flag.String("ctx", "", "input context to encrypt")
key := flag.String("key", "", "input encrypt key")
flag.Parse()
if *ctx == "" {
fmt.Println("input -ctx/-key xxx")
os.Exit(1)
}
if *key == "" {
*key = "deepglint"
}
len_ctx := len(*ctx)
len_key := len(*key)
ctx_enc := make([]byte, len_ctx)
ctx_dec := make([]byte, len_ctx)
for i := 0; i < len_ctx; i++ {
ctx_enc[i] = (*ctx)[i] ^ (*key)[i%len_key]
}
for i := 0; i < len_ctx; i++ {
ctx_dec[i] = ctx_enc[i] ^ (*key)[i%len_key]
}
fmt.Println("origin:", *ctx)
fmt.Println("key:", *key)
fmt.Println("encrypt:", ctx_enc)
fmt.Println("decrypt:", string(ctx_dec))
}