Push Notifications by 2018

Push Notifications by 2018

Author:2018
Language: eng
Format: epub
Publisher: Ray Wenderlich


Implementing the ROT13 cipher

In your Payload Modification target create a new Swift file named ROT13.swift and paste this code into it:

import Foundation struct ROT13 { static let shared = ROT13() private let upper = Array("ABCDEFGHIJKLMNOPQRSTUVWXYZ") private let lower = Array("abcdefghijklmnopqrstuvwxyz") private var mapped: [Character: Character] = [:] private init() { for i in 0 ..< 26 { let idx = (i + 13) % 26 mapped[upper[i]] = upper[idx] mapped[lower[i]] = lower[idx] } } public func decrypt(_ str: String) -> String { return String(str.map { mapped[$0] ?? $0 }) } }

You can find many different ways of implementing this cipher in Swift. The above is just a quick and dirty way to handle the American English alphabet.

Obviously, the above code makes a nice sample for a book as it doesn’t require downloads and configuration. However, for real security, you should look to something like the CryptoSwift (https://cryptoswift.io/) library.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.