Sha256: eeff80c0878c8e0f1f0125a6cfb894d0050c8767d1d8007cb435369ea8b83689

Contents?: true

Size: 1.32 KB

Versions: 207

Compression:

Stored size: 1.32 KB

Contents

import Foundation

struct Atbash {

    private static func stripWhiteSpaceAndPunctuations(_ input: String) -> String {
        var returnString = ""
        input.characters.forEach {
            if !" ,.".contains(String($0)) {
                returnString.append($0)
            }
        }

        return returnString
    }

    static let cipherDictApply: [Character : Character] = ["a": "z", "b": "y", "c": "x", "d": "w", "e": "v", "f": "u", "g": "t", "h": "s", "i": "r", "j": "q", "k": "p", "l": "o", "m": "n", "n": "m", "o": "l", "p": "k", "q": "j", "r": "i", "s": "h", "t": "g", "u": "f", "v": "e", "w": "d", "x": "c", "y": "b", "z": "a"]

    static func encode( _ valueIn: String) -> String {
        let value = stripWhiteSpaceAndPunctuations(valueIn.lowercased()  )

        var text2return = ""

        for each in value.characters {
            text2return.append(cipherDictApply[each] ?? each )
        }
        return insertSpace5th(text2return)
    }

    static func insertSpace5th(_ value: String) -> String {
        var tempCounter = 0
        var tempString: String = ""
        for each in value.characters {
            if tempCounter % 5 == 0 && tempCounter != 0 {
                tempString += " \(each)"
            } else { tempString += "\(each)" }
            tempCounter += 1
        }
        return tempString
    }

}

Version data entries

207 entries across 207 versions & 1 rubygems

Version Path
trackler-2.2.1.60 tracks/swift/exercises/atbash-cipher/Sources/AtbashExample.swift
trackler-2.2.1.59 tracks/swift/exercises/atbash-cipher/Sources/AtbashExample.swift
trackler-2.2.1.58 tracks/swift/exercises/atbash-cipher/Sources/AtbashExample.swift
trackler-2.2.1.57 tracks/swift/exercises/atbash-cipher/Sources/AtbashExample.swift
trackler-2.2.1.56 tracks/swift/exercises/atbash-cipher/Sources/AtbashExample.swift
trackler-2.2.1.55 tracks/swift/exercises/atbash-cipher/Sources/AtbashExample.swift
trackler-2.2.1.54 tracks/swift/exercises/atbash-cipher/Sources/AtbashExample.swift
trackler-2.2.1.53 tracks/swift/exercises/atbash-cipher/Sources/AtbashExample.swift
trackler-2.2.1.52 tracks/swift/exercises/atbash-cipher/Sources/AtbashExample.swift
trackler-2.2.1.51 tracks/swift/exercises/atbash-cipher/Sources/AtbashExample.swift
trackler-2.2.1.50 tracks/swift/exercises/atbash-cipher/Sources/AtbashExample.swift
trackler-2.2.1.49 tracks/swift/exercises/atbash-cipher/Sources/AtbashExample.swift
trackler-2.2.1.48 tracks/swift/exercises/atbash-cipher/Sources/AtbashExample.swift
trackler-2.2.1.47 tracks/swift/exercises/atbash-cipher/Sources/AtbashExample.swift
trackler-2.2.1.46 tracks/swift/exercises/atbash-cipher/Sources/AtbashExample.swift
trackler-2.2.1.45 tracks/swift/exercises/atbash-cipher/Sources/AtbashExample.swift
trackler-2.2.1.44 tracks/swift/exercises/atbash-cipher/Sources/AtbashExample.swift
trackler-2.2.1.43 tracks/swift/exercises/atbash-cipher/Sources/AtbashExample.swift
trackler-2.2.1.42 tracks/swift/exercises/atbash-cipher/Sources/AtbashExample.swift
trackler-2.2.1.41 tracks/swift/exercises/atbash-cipher/Sources/AtbashExample.swift