finished all features
This commit is contained in:
parent
f8c18022ae
commit
092f877fe1
32
Go/main.go
32
Go/main.go
@ -3,29 +3,45 @@ package main
|
||||
import (
|
||||
"fmt"
|
||||
"flag"
|
||||
"one-time-pad-utils/otp_gen"
|
||||
"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")
|
||||
var decryptmessage = flag.String("decrypt", "", "Specify a message you wish to decrypt")
|
||||
var otpkey = flag.String("key", "", "The specify required key for encryption and decryption")
|
||||
var _ = encryptmessage
|
||||
var _ = decryptmessage
|
||||
var _ = otpkey
|
||||
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", otpgen.GenerateOTP(*genpadchunks))
|
||||
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
|
||||
}
|
||||
|
||||
|
Binary file not shown.
47
Go/otp_decrypt/otp_decrypt.go
Normal file
47
Go/otp_decrypt/otp_decrypt.go
Normal file
@ -0,0 +1,47 @@
|
||||
package otpdecrypt
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"one-time-pad-utils/pad_definitions"
|
||||
)
|
||||
|
||||
func OTPDecrypt(message string, key string) string {
|
||||
message = strings.Replace(message, " ", "", -1)
|
||||
messagesplit := strings.Split(message,"")
|
||||
var messagesplitint []int
|
||||
|
||||
key = strings.Replace(key, " ", "", -1)
|
||||
keysplit := strings.Split(key,"")
|
||||
var keysplitint []int
|
||||
|
||||
for _, char := range messagesplit {
|
||||
for n, c := range paddefinitions.NumToCharMap{
|
||||
if c == strings.ToUpper(char) {
|
||||
messagesplitint = append(messagesplitint, n)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for _, char := range keysplit {
|
||||
for n, c := range paddefinitions.NumToCharMap{
|
||||
if c == strings.ToUpper(char) {
|
||||
keysplitint = append(keysplitint, n)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if len(keysplitint) < len(messagesplitint) {
|
||||
return ("KEY TOO SHORT TO DECRYPT MESSAGE")
|
||||
}
|
||||
|
||||
var decryptedmessage []string
|
||||
|
||||
for pos, messagenum := range messagesplitint{
|
||||
decryptedmessage = append(decryptedmessage, paddefinitions.NumToCharMap[(((messagenum - keysplitint[pos]) % 35) + 35) % 35]) // crazy modulo for decryption
|
||||
|
||||
}
|
||||
|
||||
return (strings.Join(decryptedmessage, ""))
|
||||
}
|
@ -39,13 +39,11 @@ func OTPEncrypt(message string, key string) string {
|
||||
var encryptedmessage []string
|
||||
|
||||
for pos, messagenum := range messagesplitint{
|
||||
if pos != 0 && pos % 5 == 0 {
|
||||
encryptedmessage = append(encryptedmessage, " ")
|
||||
}
|
||||
encryptedmessage = append(encryptedmessage, paddefinitions.NumToCharMap[(messagenum + keysplitint[pos]) % 35])
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
return (strings.Join(encryptedmessage, ""))
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
//One-Time Pad generator
|
||||
|
||||
package otpgen
|
||||
package otpgenerate
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
Loading…
x
Reference in New Issue
Block a user