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{
|
for n, c := range paddefinitions.NumToCharMap{
|
||||||
if c == strings.ToUpper(char) {
|
if c == strings.ToUpper(char) {
|
||||||
messagesplitint = append(messagesplitint, n)
|
messagesplitint = append(messagesplitint, n)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -39,7 +39,7 @@ 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]) % 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{
|
for n, c := range paddefinitions.NumToCharMap{
|
||||||
if c == strings.ToUpper(char) {
|
if c == strings.ToUpper(char) {
|
||||||
messagesplitint = append(messagesplitint, n)
|
messagesplitint = append(messagesplitint, n)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -42,7 +42,7 @@ func OTPEncrypt(message string, key string) string {
|
|||||||
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]) % 35])
|
encryptedmessage = append(encryptedmessage, paddefinitions.NumToCharMap[(messagenum + keysplitint[pos]) % 36])
|
||||||
}
|
}
|
||||||
|
|
||||||
return (strings.Join(encryptedmessage, ""))
|
return (strings.Join(encryptedmessage, ""))
|
||||||
|
|||||||
@@ -1,40 +1,40 @@
|
|||||||
package paddefinitions
|
package paddefinitions
|
||||||
|
|
||||||
var NumToCharMap = map[int]string{
|
var NumToCharMap = map[int]string{
|
||||||
0: "9",
|
0: "A",
|
||||||
1: "A",
|
1: "B",
|
||||||
2: "B",
|
2: "C",
|
||||||
3: "C",
|
3: "D",
|
||||||
4: "D",
|
4: "E",
|
||||||
5: "E",
|
5: "F",
|
||||||
6: "F",
|
6: "G",
|
||||||
7: "G",
|
7: "H",
|
||||||
8: "H",
|
8: "I",
|
||||||
9: "I",
|
9: "J",
|
||||||
10: "J",
|
10: "K",
|
||||||
11: "K",
|
11: "L",
|
||||||
12: "L",
|
12: "M",
|
||||||
13: "M",
|
13: "N",
|
||||||
14: "N",
|
14: "O",
|
||||||
15: "O",
|
15: "P",
|
||||||
16: "P",
|
16: "Q",
|
||||||
17: "Q",
|
17: "R",
|
||||||
18: "R",
|
18: "S",
|
||||||
19: "S",
|
19: "T",
|
||||||
20: "T",
|
20: "U",
|
||||||
21: "U",
|
21: "V",
|
||||||
22: "V",
|
22: "W",
|
||||||
23: "W",
|
23: "X",
|
||||||
24: "X",
|
24: "Y",
|
||||||
25: "Y",
|
25: "Z",
|
||||||
26: "Z",
|
26: "0",
|
||||||
27: "0",
|
27: "1",
|
||||||
28: "1",
|
28: "2",
|
||||||
29: "2",
|
29: "3",
|
||||||
30: "3",
|
30: "4",
|
||||||
31: "4",
|
31: "5",
|
||||||
32: "5",
|
32: "6",
|
||||||
33: "6",
|
33: "7",
|
||||||
34: "7",
|
34: "8",
|
||||||
35: "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