refactored one-time-pad system and added modulus cheat sheet
This commit is contained in:
BIN
35mm_film_canister/instructions.odt
Normal file
BIN
35mm_film_canister/instructions.odt
Normal file
Binary file not shown.
BIN
Go/one-time-pad-utils
Executable file
BIN
Go/one-time-pad-utils
Executable file
Binary file not shown.
@@ -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
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -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, ""))
|
||||
|
||||
@@ -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.
Reference in New Issue
Block a user