Fornite Cipher Decoder in Swift
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
decode(message: "3.12.17.8.7.18") | |
decode(message: "1.17.23.9.14. 19.19.24.1.21.6") | |
decode(message: "19.19.19.1.27. 1.22. 22.16.15.10.20.21. 2.17.26.12") | |
decode(message: "12.18.15.5.14.25. 14.4.2.22") | |
decode(message: "19.11.2.20.22.5.20.8.4. 22.13.1.4.19") | |
func decode(message: String) { | |
print("Deciphering message \(message)") | |
let cipher = ["0", "3", "1", "0", "2", "0", "2", "3"] | |
let alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" | |
let normalizedMessage = message.replacing(" ", with: " .") | |
let messageArray = normalizedMessage.split(separator: ".") | |
var charIndex = 0 | |
for messageChar in messageArray { | |
var decodedChar:Character | |
if(messageChar == " "){ | |
decodedChar = " " | |
} | |
else{ | |
let cipherCharIndex = charIndex % cipher.count | |
let calcChar = Int(messageChar)! - Int(cipher[cipherCharIndex])! - 1 | |
decodedChar = alphabet.uppercased()[alphabet.index(alphabet.startIndex, offsetBy: calcChar)]; | |
charIndex += 1 | |
} | |
print("\(decodedChar)", terminator: "") | |
} | |
print("\n") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment