2024-08-09 14:58:37 -04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"flag"
|
2024-08-09 17:38:44 -04:00
|
|
|
"math"
|
|
|
|
"strings"
|
|
|
|
"one-time-pad-utils/otp_generate"
|
2024-08-09 14:58:37 -04:00
|
|
|
"one-time-pad-utils/otp_encrypt"
|
2024-08-09 17:38:44 -04:00
|
|
|
"one-time-pad-utils/otp_decrypt"
|
2024-08-09 14:58:37 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func main(){
|
|
|
|
var genpad = flag.Bool("generate", false, "Generate a new One-Time Pad using CSPRNG")
|
|
|
|
var genpadchunks = flag.Int("chunks", 200, "Specify the amount of chunks to generate")
|
2024-08-09 17:38:44 -04:00
|
|
|
var encryptmessage = flag.String("encrypt", "", "Specify a message you wish to encrypt (use quotes if you have spaces)")
|
|
|
|
var decryptmessage = flag.String("decrypt", "", "Specify a message you wish to decrypt (use quotes if you have spaces)")
|
|
|
|
var otpkey = flag.String("key", "", "The specify a key for encryption (optional) and decryption (required) (use quotes if you have spaces)")
|
2024-08-09 14:58:37 -04:00
|
|
|
|
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
if *genpad {
|
2024-08-09 17:38:44 -04:00
|
|
|
fmt.Printf("%v\n", otpgenerate.GenerateOTP(*genpadchunks))
|
2024-08-09 14:58:37 -04:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if *encryptmessage != "" {
|
2024-08-09 17:38:44 -04:00
|
|
|
if *otpkey != ""{
|
|
|
|
fmt.Printf("%v\n", otpencrypt.OTPEncrypt(*encryptmessage,*otpkey))
|
|
|
|
} else {
|
|
|
|
encryptmessagestring := strings.Replace(*encryptmessage, " ", "", -1)
|
|
|
|
lenofmessage := math.Ceil(float64(len(encryptmessagestring))/float64(5))
|
|
|
|
generated_key := otpgenerate.GenerateOTP(int(lenofmessage))
|
|
|
|
fmt.Printf("GENERATED NEW KEY SINCE NONE WAS SPECIFIED:\n%v\n\n%v\n", generated_key, otpencrypt.OTPEncrypt(*encryptmessage, generated_key))
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if *decryptmessage != "" {
|
|
|
|
if *otpkey != ""{
|
|
|
|
fmt.Printf("%v\n", otpdecrypt.OTPDecrypt(*decryptmessage,*otpkey))
|
|
|
|
} else {
|
|
|
|
fmt.Println("PLEASE SUPPLY A KEY")
|
|
|
|
}
|
2024-08-09 14:58:37 -04:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
flag.PrintDefaults()
|
|
|
|
}
|