Compare commits

..

10 Commits

Author SHA1 Message Date
Lexzach
9d9ab04c55 updated README.md 2024-08-09 22:06:53 -04:00
Lexzach
092f877fe1 finished all features 2024-08-09 17:38:44 -04:00
lexzach
f8c18022ae moved some stuff around 2024-08-09 15:04:25 -04:00
lexzach
c3cb8eaf83 otp generation and encryption added with go 2024-08-09 14:58:37 -04:00
lexzach
dacdf6dcd3 updated formatting in readme 2024-08-09 12:17:49 -04:00
lexzach
1fa9a9b36b updated README.md 2024-08-09 12:16:50 -04:00
lexzach
85c4925141 added alternate chart 2024-08-09 11:13:59 -04:00
lexzach
6ca10dffc9 reformatted document thx Sour Dani 2024-08-09 11:05:40 -04:00
lexzach
e63fc0fa77 updated readme 2024-08-08 18:35:09 -04:00
lexzach
3690ff2a59 doc written 2024-08-08 18:24:16 -04:00
11 changed files with 236 additions and 2 deletions

3
Go/go.mod Normal file
View File

@@ -0,0 +1,3 @@
module one-time-pad-utils
go 1.19

49
Go/main.go Normal file
View File

@@ -0,0 +1,49 @@
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()
}

View 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, ""))
}

View File

@@ -0,0 +1,49 @@
package otpencrypt
import (
"strings"
"one-time-pad-utils/pad_definitions"
)
func OTPEncrypt(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 ENCRYPT MESSAGE")
}
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, ""))
}

View File

@@ -0,0 +1,33 @@
//One-Time Pad generator
package otpgenerate
import (
"crypto/rand"
"math/big"
"one-time-pad-utils/pad_definitions"
)
func GenerateOTP(chunks int) string {
count := 1
otpstring := ""
for count < (chunks*5)+1{
n, err := rand.Int(rand.Reader, big.NewInt(36)) // generate new cryptographically secure random number
if err != nil {
panic(err)
}
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 % 50 == 0{
otpstring += "\n"
} else {
otpstring += " "
}
}
count+=1
}
return otpstring
}

View File

@@ -0,0 +1,40 @@
package paddefinitions
var NumToCharMap = map[int]string{
0: "9",
1: "A",
2: "B",
3: "C",
4: "D",
5: "E",
6: "F",
7: "G",
8: "H",
9: "I",
10: "J",
11: "K",
12: "L",
13: "M",
14: "N",
15: "O",
16: "P",
17: "Q",
18: "R",
19: "S",
20: "T",
21: "U",
22: "V",
23: "W",
24: "X",
25: "Y",
26: "Z",
27: "0",
28: "1",
29: "2",
30: "3",
31: "4",
32: "5",
33: "6",
34: "7",
35: "8",
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -1,3 +1,16 @@
# dice-one-time-pad # 🎲 Dice One-Time Pads:
A technique to make uncrackable encrypted messages using two six-sided die.
### 📄 [Main Instructions](https://code.lexza.ch/Lexzach/dice-one-time-pad/raw/branch/main/Instructions/dice-one-time-pad.pdf)
### 🔢 [Alternate Chart](https://code.lexza.ch/Lexzach/dice-one-time-pad/raw/branch/main/Instructions/alternate-chart.pdf)
If you have a less security critical use of this One-Time Pad technique, you can use the [program written in Go](https://code.lexza.ch/Lexzach/dice-one-time-pad/src/branch/main/Go) within this repository to greatly speed up the key generation, encryption, and decryption process. This program is 100% compatible with the manual method, but is less secure because of the [CSPRNG](https://en.wikipedia.org/wiki/Cryptographically_secure_pseudorandom_number_generator) utilized as opposed to the (effectively) true random numbers of a dice.
A technique for generating entirely offline one time pads. ### How does this all work?
([Wikipedia](https://en.wikipedia.org/wiki/One-time_pad))<br>
One-time pads are a method of encryption which, if done right, result in a message that is *literally impossible* to decrypt without the key. The absolute beauty of this encryption method is that it's *extremely* easy to implement ***by hand***.<br>
However, there are four conditions that must be true for this encryption method to truly be unbreakable:
- The key must be as long as the message you wish to encrypt.
- The key must be generated using truly random methods. (which the Go program is ***not***)
- The key must never be reused.
- The key must be kept a complete secret.
<br><br>
In order to comply with the second condition, two regular 6 sided die will be used to generate the key for encryption and decryption.