Adjust some Go related things
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
Go/dotp
|
||||||
20
Go/main.go
20
Go/main.go
@@ -1,16 +1,16 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
otpdecrypt "dotp/otp_decrypt"
|
||||||
|
otpencrypt "dotp/otp_encrypt"
|
||||||
|
otpgenerate "dotp/otp_generate"
|
||||||
"flag"
|
"flag"
|
||||||
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
"strings"
|
"strings"
|
||||||
"one-time-pad-utils/otp_generate"
|
|
||||||
"one-time-pad-utils/otp_encrypt"
|
|
||||||
"one-time-pad-utils/otp_decrypt"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func main(){
|
func main() {
|
||||||
var genpad = flag.Bool("generate", false, "Generate a new One-Time Pad using CSPRNG")
|
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 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 encryptmessage = flag.String("encrypt", "", "Specify a message you wish to encrypt (use quotes if you have spaces)")
|
||||||
@@ -25,11 +25,11 @@ func main(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
if *encryptmessage != "" {
|
if *encryptmessage != "" {
|
||||||
if *otpkey != ""{
|
if *otpkey != "" {
|
||||||
fmt.Printf("%v\n", otpencrypt.OTPEncrypt(*encryptmessage,*otpkey))
|
fmt.Printf("%v\n", otpencrypt.OTPEncrypt(*encryptmessage, *otpkey))
|
||||||
} else {
|
} else {
|
||||||
encryptmessagestring := strings.Replace(*encryptmessage, " ", "", -1)
|
encryptmessagestring := strings.Replace(*encryptmessage, " ", "", -1)
|
||||||
lenofmessage := math.Ceil(float64(len(encryptmessagestring))/float64(5))
|
lenofmessage := math.Ceil(float64(len(encryptmessagestring)) / float64(5))
|
||||||
generated_key := otpgenerate.GenerateOTP(int(lenofmessage))
|
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))
|
fmt.Printf("GENERATED NEW KEY SINCE NONE WAS SPECIFIED:\n%v\n\n%v\n", generated_key, otpencrypt.OTPEncrypt(*encryptmessage, generated_key))
|
||||||
}
|
}
|
||||||
@@ -37,8 +37,8 @@ func main(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
if *decryptmessage != "" {
|
if *decryptmessage != "" {
|
||||||
if *otpkey != ""{
|
if *otpkey != "" {
|
||||||
fmt.Printf("%v\n", otpdecrypt.OTPDecrypt(*decryptmessage,*otpkey))
|
fmt.Printf("%v\n", otpdecrypt.OTPDecrypt(*decryptmessage, *otpkey))
|
||||||
} else {
|
} else {
|
||||||
fmt.Println("PLEASE SUPPLY A KEY")
|
fmt.Println("PLEASE SUPPLY A KEY")
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
@@ -1,21 +1,21 @@
|
|||||||
package otpdecrypt
|
package otpdecrypt
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
paddefinitions "dotp/pad_definitions"
|
||||||
"strings"
|
"strings"
|
||||||
"one-time-pad-utils/pad_definitions"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func OTPDecrypt(message string, key string) string {
|
func OTPDecrypt(message string, key string) string {
|
||||||
message = strings.Replace(message, " ", "", -1)
|
message = strings.Replace(message, " ", "", -1)
|
||||||
messagesplit := strings.Split(message,"")
|
messagesplit := strings.Split(message, "")
|
||||||
var messagesplitint []int
|
var messagesplitint []int
|
||||||
|
|
||||||
key = strings.Replace(key, " ", "", -1)
|
key = strings.Replace(key, " ", "", -1)
|
||||||
keysplit := strings.Split(key,"")
|
keysplit := strings.Split(key, "")
|
||||||
var keysplitint []int
|
var keysplitint []int
|
||||||
|
|
||||||
for _, char := range messagesplit {
|
for _, char := range messagesplit {
|
||||||
for n, c := range paddefinitions.NumToCharMap{
|
for n, c := range paddefinitions.NumToCharMap {
|
||||||
if c == strings.ToUpper(char) {
|
if c == strings.ToUpper(char) {
|
||||||
messagesplitint = append(messagesplitint, n)
|
messagesplitint = append(messagesplitint, n)
|
||||||
|
|
||||||
@@ -24,7 +24,7 @@ func OTPDecrypt(message string, key string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, char := range keysplit {
|
for _, char := range keysplit {
|
||||||
for n, c := range paddefinitions.NumToCharMap{
|
for n, c := range paddefinitions.NumToCharMap {
|
||||||
if c == strings.ToUpper(char) {
|
if c == strings.ToUpper(char) {
|
||||||
keysplitint = append(keysplitint, n)
|
keysplitint = append(keysplitint, n)
|
||||||
|
|
||||||
@@ -38,8 +38,8 @@ func OTPDecrypt(message string, key string) string {
|
|||||||
|
|
||||||
var decryptedmessage []string
|
var decryptedmessage []string
|
||||||
|
|
||||||
for pos, messagenum := range messagesplitint{
|
for pos, messagenum := range messagesplitint {
|
||||||
decryptedmessage = append(decryptedmessage, paddefinitions.NumToCharMap[(((messagenum - keysplitint[pos]) % 36) + 36) % 36]) // crazy modulo for decryption
|
decryptedmessage = append(decryptedmessage, paddefinitions.NumToCharMap[(((messagenum-keysplitint[pos])%36)+36)%36]) // crazy modulo for decryption
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,21 +1,21 @@
|
|||||||
package otpencrypt
|
package otpencrypt
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
paddefinitions "dotp/pad_definitions"
|
||||||
"strings"
|
"strings"
|
||||||
"one-time-pad-utils/pad_definitions"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func OTPEncrypt(message string, key string) string {
|
func OTPEncrypt(message string, key string) string {
|
||||||
message = strings.Replace(message, " ", "", -1)
|
message = strings.Replace(message, " ", "", -1)
|
||||||
messagesplit := strings.Split(message,"")
|
messagesplit := strings.Split(message, "")
|
||||||
var messagesplitint []int
|
var messagesplitint []int
|
||||||
|
|
||||||
key = strings.Replace(key, " ", "", -1)
|
key = strings.Replace(key, " ", "", -1)
|
||||||
keysplit := strings.Split(key,"")
|
keysplit := strings.Split(key, "")
|
||||||
var keysplitint []int
|
var keysplitint []int
|
||||||
|
|
||||||
for _, char := range messagesplit {
|
for _, char := range messagesplit {
|
||||||
for n, c := range paddefinitions.NumToCharMap{
|
for n, c := range paddefinitions.NumToCharMap {
|
||||||
if c == strings.ToUpper(char) {
|
if c == strings.ToUpper(char) {
|
||||||
messagesplitint = append(messagesplitint, n)
|
messagesplitint = append(messagesplitint, n)
|
||||||
|
|
||||||
@@ -24,7 +24,7 @@ func OTPEncrypt(message string, key string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, char := range keysplit {
|
for _, char := range keysplit {
|
||||||
for n, c := range paddefinitions.NumToCharMap{
|
for n, c := range paddefinitions.NumToCharMap {
|
||||||
if c == strings.ToUpper(char) {
|
if c == strings.ToUpper(char) {
|
||||||
keysplitint = append(keysplitint, n)
|
keysplitint = append(keysplitint, n)
|
||||||
|
|
||||||
@@ -38,11 +38,11 @@ func OTPEncrypt(message string, key string) string {
|
|||||||
|
|
||||||
var encryptedmessage []string
|
var encryptedmessage []string
|
||||||
|
|
||||||
for pos, messagenum := range messagesplitint{
|
for pos, messagenum := range messagesplitint {
|
||||||
if pos != 0 && pos % 5 == 0 {
|
if pos != 0 && pos%5 == 0 {
|
||||||
encryptedmessage = append(encryptedmessage, " ")
|
encryptedmessage = append(encryptedmessage, " ")
|
||||||
}
|
}
|
||||||
encryptedmessage = append(encryptedmessage, paddefinitions.NumToCharMap[(messagenum + keysplitint[pos]) % 36])
|
encryptedmessage = append(encryptedmessage, paddefinitions.NumToCharMap[(messagenum+keysplitint[pos])%36])
|
||||||
}
|
}
|
||||||
|
|
||||||
return (strings.Join(encryptedmessage, ""))
|
return (strings.Join(encryptedmessage, ""))
|
||||||
|
|||||||
@@ -4,29 +4,28 @@ package otpgenerate
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
|
paddefinitions "dotp/pad_definitions"
|
||||||
"math/big"
|
"math/big"
|
||||||
"one-time-pad-utils/pad_definitions"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
func GenerateOTP(chunks int) string {
|
func GenerateOTP(chunks int) string {
|
||||||
count := 1
|
count := 1
|
||||||
otpstring := ""
|
otpstring := ""
|
||||||
|
|
||||||
for count < (chunks*5)+1{
|
for count < (chunks*5)+1 {
|
||||||
n, err := rand.Int(rand.Reader, big.NewInt(36)) // generate new cryptographically secure random number
|
n, err := rand.Int(rand.Reader, big.NewInt(36)) // generate new cryptographically secure random number
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
otpstring += paddefinitions.NumToCharMap[int(n.Int64())] // print that number using the character map
|
otpstring += paddefinitions.NumToCharMap[int(n.Int64())] // print that number using the character map
|
||||||
if count % 5 == 0 { // add a space every 5 characters, newline after 10 chunks
|
if count%5 == 0 { // add a space every 5 characters, newline after 10 chunks
|
||||||
if count % 50 == 0{
|
if count%50 == 0 {
|
||||||
otpstring += "\n"
|
otpstring += "\n"
|
||||||
} else {
|
} else {
|
||||||
otpstring += " "
|
otpstring += " "
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
count+=1
|
count += 1
|
||||||
}
|
}
|
||||||
|
|
||||||
return otpstring
|
return otpstring
|
||||||
|
|||||||
Reference in New Issue
Block a user