finished all features
This commit is contained in:
47
Go/otp_decrypt/otp_decrypt.go
Normal file
47
Go/otp_decrypt/otp_decrypt.go
Normal 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, ""))
|
||||
}
|
Reference in New Issue
Block a user