Created
June 5, 2018 23:07
-
-
Save trennepohl/06d2a84563978107e7670093238cb272 to your computer and use it in GitHub Desktop.
Cifra de césar
This file contains hidden or 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 main | |
import ( | |
"fmt" | |
"strings" | |
) | |
func main() { | |
var input string | |
fmt.Println("Insira o texto") | |
fmt.Scan(&input) | |
encryptedString := encrypt(strings.ToLower(input)) | |
fmt.Println(encryptedString) | |
fmt.Println(decrypt(encryptedString)) | |
} | |
func encrypt(plainText string) string { | |
var encodedString []rune | |
for _, value := range plainText { | |
if rune(value) == 122 { | |
encodedString = append(encodedString, rune('a')+2) | |
} else { | |
encodedString = append(encodedString, value+3) | |
} | |
} | |
return string(encodedString) | |
} | |
func decrypt(encodedString string) string { | |
var plainText []rune | |
for _, value := range encodedString { | |
if rune(value) == 97 { | |
plainText = append(plainText, rune('z')-2) | |
} else { | |
plainText = append(plainText, value-3) | |
} | |
} | |
return string(plainText) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment