package main

import (
	"fmt"
	"flag"
	"math"
	"strings"
	"one-time-pad-utils/otp_generate"
	"one-time-pad-utils/otp_encrypt"
	"one-time-pad-utils/otp_decrypt"
)

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")
	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)")

	flag.Parse()

	if *genpad {
		fmt.Printf("%v\n", otpgenerate.GenerateOTP(*genpadchunks))
		return
	}

	if *encryptmessage != "" {
		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")
		}
		return
	}
	
	flag.PrintDefaults()
}
