-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
42 lines (37 loc) · 787 Bytes
/
main.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
package main
import (
"crypto/cipher"
"crypto/des"
"encoding/base64"
"flag"
"fmt"
"os"
)
func main() {
var (
iv = []uint8{18, 52, 86, 120, 144, 171, 205, 239}
key = "88916830"
enc string
)
flag.StringVar(&enc, "enc", "", "Input encryption text.")
flag.Parse()
if enc == "" {
flag.Usage()
os.Exit(0)
}
v1, _ := base64.StdEncoding.DecodeString(enc)
block, err := des.NewCipher([]byte(key))
if err != nil {
panic(err)
}
mode := cipher.NewCBCDecrypter(block, iv)
plaintext := make([]byte, len(v1))
mode.CryptBlocks(plaintext, v1)
plaintext = PKCS5UnPadding(plaintext)
fmt.Println(string(plaintext))
}
func PKCS5UnPadding(origData []byte) []byte {
length := len(origData)
unpadding := int(origData[length-1])
return origData[:(length - unpadding)]
}