Sha256: e9c5722bc3dd7d533d966ed94fd4ed7b1cc1338d9330514e1138d32d4b38c271

Contents?: true

Size: 748 Bytes

Versions: 118

Compression:

Stored size: 748 Bytes

Contents

struct RotationalCipher {

    static func rotate(_ target: String, ROT: Int) -> String {

        var result = ""

        target.unicodeScalars.forEach { unicode in

            switch unicode.value {
            case 65...90: // A to Z
                var scalar = unicode.value + UInt32(ROT)
                if scalar > 90 { scalar -= 26 }
                result.append(Character(UnicodeScalar(scalar)!))

            case 97...122: // a to z
                var scalar = unicode.value + UInt32(ROT)
                if scalar > 122 { scalar -= 26 }
                result.append(Character(UnicodeScalar(scalar)!))

            default:
                result.append(Character(unicode))
            }

        }

        return result

    }

}

Version data entries

118 entries across 118 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/swift/exercises/rotational-cipher/Sources/RotationalCipherExample.swift
trackler-2.2.1.179 tracks/swift/exercises/rotational-cipher/Sources/RotationalCipherExample.swift
trackler-2.2.1.178 tracks/swift/exercises/rotational-cipher/Sources/RotationalCipherExample.swift
trackler-2.2.1.177 tracks/swift/exercises/rotational-cipher/Sources/RotationalCipherExample.swift
trackler-2.2.1.176 tracks/swift/exercises/rotational-cipher/Sources/RotationalCipherExample.swift
trackler-2.2.1.175 tracks/swift/exercises/rotational-cipher/Sources/RotationalCipherExample.swift
trackler-2.2.1.174 tracks/swift/exercises/rotational-cipher/Sources/RotationalCipherExample.swift
trackler-2.2.1.173 tracks/swift/exercises/rotational-cipher/Sources/RotationalCipherExample.swift
trackler-2.2.1.172 tracks/swift/exercises/rotational-cipher/Sources/RotationalCipherExample.swift
trackler-2.2.1.171 tracks/swift/exercises/rotational-cipher/Sources/RotationalCipherExample.swift
trackler-2.2.1.170 tracks/swift/exercises/rotational-cipher/Sources/RotationalCipherExample.swift
trackler-2.2.1.169 tracks/swift/exercises/rotational-cipher/Sources/RotationalCipherExample.swift
trackler-2.2.1.167 tracks/swift/exercises/rotational-cipher/Sources/RotationalCipherExample.swift
trackler-2.2.1.166 tracks/swift/exercises/rotational-cipher/Sources/RotationalCipherExample.swift
trackler-2.2.1.165 tracks/swift/exercises/rotational-cipher/Sources/RotationalCipherExample.swift
trackler-2.2.1.164 tracks/swift/exercises/rotational-cipher/Sources/RotationalCipherExample.swift
trackler-2.2.1.163 tracks/swift/exercises/rotational-cipher/Sources/RotationalCipherExample.swift
trackler-2.2.1.162 tracks/swift/exercises/rotational-cipher/Sources/RotationalCipherExample.swift
trackler-2.2.1.161 tracks/swift/exercises/rotational-cipher/Sources/RotationalCipherExample.swift
trackler-2.2.1.160 tracks/swift/exercises/rotational-cipher/Sources/RotationalCipherExample.swift