Created
August 21, 2022 03:31
-
-
Save nasustim/e720bc4c4a8337eacf31117a8f7b1b29 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package rotxiii | |
func Decode(src string) string { | |
SHIFT_LENGTH := 13 | |
ALPHABET_LENGTH := 26 | |
SKIP_SEQUENCES := []byte{' ', '.'} | |
b := []byte(src) | |
r := make([]byte, len(src)) | |
for i, _ := range r { | |
hitSkipSeq := false | |
for _, ss := range SKIP_SEQUENCES { | |
if b[i] == ss { | |
hitSkipSeq = true | |
r[i] = ss | |
break | |
} | |
} | |
if hitSkipSeq { | |
continue | |
} | |
var limitSeq []byte | |
if 'A' <= b[i] && b[i] <= 'Z' { | |
limitSeq = []byte{'A', 'Z'} | |
} else { | |
limitSeq = []byte{'a', 'z'} | |
} | |
decc := b[i] - byte(SHIFT_LENGTH) | |
if !(limitSeq[0] <= decc && decc <= limitSeq[1]) { | |
decc += byte(ALPHABET_LENGTH) | |
} | |
r[i] = decc | |
} | |
return string(r) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment