package main

import (
	"encoding/hex"
	"fmt"
	"runtime"
	"time"

	zcrypt "github.com/zeevdiukman/z/zcrypt"
)

func main() {
	t := time.Now()
	key := "1b1ef1cf714a412d57ec7be1647e6e1e7f8141a1cd009dd13b52041e5c62dbd6"
	keyBytes, _ := hex.DecodeString(key)
	// keyBytes := zcrypt.GenerateAESKey()
	// key := hex.EncodeToString(keyBytes)
	// fmt.Println(hex.EncodeToString(key[:]))
	// key := []byte("59e34dbbfb51ffb24e84eb6a0b4301ff")
	plaintext := "hello, world!"

	encryptedText, err := zcrypt.Encrypt(plaintext, keyBytes)
	if err != nil {
		fmt.Println("Error encrypting:", err)
		return
	}
	decryptedText, err := zcrypt.Decrypt(encryptedText, keyBytes)
	if err != nil {
		fmt.Println("Error decrypting:", err)
		return
	}
	tt := time.Since(t)

	fmt.Println("Key:", key)
	fmt.Println("Encrypted:", encryptedText)
	fmt.Println("Decrypted:", decryptedText)
	fmt.Println("Generated in", tt)
	PrintOldStyleMetrics()

}

func PrintOldStyleMetrics() {
	runtime.GOMAXPROCS(4)
	fmt.Printf("Operating system is: %s\n", runtime.GOOS)
	// Get number of go routines, max os threads allocated to process and host number of cpus
	numGoroutines := runtime.NumGoroutine()
	fmt.Printf("The program is using %d go routines\n", numGoroutines)
	maxThreads := runtime.GOMAXPROCS(0)
	fmt.Printf("The program is configured to %d max threads ", maxThreads)
	numCPUs := runtime.NumCPU()
	fmt.Printf("- the host has %d cpus", numCPUs)

}
