refactored one-time-pad system and added modulus cheat sheet

This commit is contained in:
2025-10-19 15:52:50 -04:00
parent 3f8c8fc026
commit fd6272eca3
9 changed files with 44 additions and 44 deletions

Binary file not shown.

BIN
Go/one-time-pad-utils Executable file

Binary file not shown.

View File

@@ -18,16 +18,16 @@ func OTPDecrypt(message string, key string) string {
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)
}
}
}
@@ -39,7 +39,7 @@ func OTPDecrypt(message string, key string) string {
var decryptedmessage []string
for pos, messagenum := range messagesplitint{
decryptedmessage = append(decryptedmessage, paddefinitions.NumToCharMap[(((messagenum - keysplitint[pos]) % 35) + 35) % 35]) // crazy modulo for decryption
decryptedmessage = append(decryptedmessage, paddefinitions.NumToCharMap[(((messagenum - keysplitint[pos]) % 36) + 36) % 36]) // crazy modulo for decryption
}

View File

@@ -18,16 +18,16 @@ func OTPEncrypt(message string, key string) string {
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)
}
}
}
@@ -42,7 +42,7 @@ func OTPEncrypt(message string, key string) string {
if pos != 0 && pos % 5 == 0 {
encryptedmessage = append(encryptedmessage, " ")
}
encryptedmessage = append(encryptedmessage, paddefinitions.NumToCharMap[(messagenum + keysplitint[pos]) % 35])
encryptedmessage = append(encryptedmessage, paddefinitions.NumToCharMap[(messagenum + keysplitint[pos]) % 36])
}
return (strings.Join(encryptedmessage, ""))

View File

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

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.