You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.1 KiB
Go
55 lines
1.1 KiB
Go
package commands
|
|
|
|
import (
|
|
"crypto/cipher"
|
|
"crypto/des"
|
|
"io"
|
|
"os"
|
|
)
|
|
|
|
type DecryptDESCommand struct {
|
|
SourceFileName string `long:"src" alias:"i" required:"true" description:"input-filename"`
|
|
DestFileName string `long:"dest" alias:"o" required:"true" description:"output-filename"`
|
|
}
|
|
|
|
func (command *DecryptDESCommand) Execute(args []string) error {
|
|
inputFile, err := os.Open(command.SourceFileName)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer inputFile.Close()
|
|
outputFile, err := os.Create(command.DestFileName)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer outputFile.Close()
|
|
|
|
inputFileStat, err := inputFile.Stat()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
pdata := make([]byte, inputFileStat.Size())
|
|
_, err = io.ReadFull(inputFile, pdata)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
block, err := des.NewTripleDESCipher([]byte("HAVNCPSCMTTUNERAIRTRACER"))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
iv := []byte("VEDKDJSP")
|
|
|
|
decrypter := cipher.NewCBCDecrypter(block, iv)
|
|
decrypted := make([]byte, len(pdata))
|
|
decrypter.CryptBlocks(decrypted, pdata)
|
|
|
|
_, err = outputFile.Write(decrypted)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|