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.159 tracks/swift/exercises/rotational-cipher/Sources/RotationalCipherExample.swift
trackler-2.2.1.158 tracks/swift/exercises/rotational-cipher/Sources/RotationalCipherExample.swift
trackler-2.2.1.157 tracks/swift/exercises/rotational-cipher/Sources/RotationalCipherExample.swift
trackler-2.2.1.156 tracks/swift/exercises/rotational-cipher/Sources/RotationalCipherExample.swift
trackler-2.2.1.155 tracks/swift/exercises/rotational-cipher/Sources/RotationalCipherExample.swift
trackler-2.2.1.154 tracks/swift/exercises/rotational-cipher/Sources/RotationalCipherExample.swift
trackler-2.2.1.153 tracks/swift/exercises/rotational-cipher/Sources/RotationalCipherExample.swift
trackler-2.2.1.152 tracks/swift/exercises/rotational-cipher/Sources/RotationalCipherExample.swift
trackler-2.2.1.151 tracks/swift/exercises/rotational-cipher/Sources/RotationalCipherExample.swift
trackler-2.2.1.150 tracks/swift/exercises/rotational-cipher/Sources/RotationalCipherExample.swift
trackler-2.2.1.149 tracks/swift/exercises/rotational-cipher/Sources/RotationalCipherExample.swift
trackler-2.2.1.148 tracks/swift/exercises/rotational-cipher/Sources/RotationalCipherExample.swift
trackler-2.2.1.147 tracks/swift/exercises/rotational-cipher/Sources/RotationalCipherExample.swift
trackler-2.2.1.146 tracks/swift/exercises/rotational-cipher/Sources/RotationalCipherExample.swift
trackler-2.2.1.145 tracks/swift/exercises/rotational-cipher/Sources/RotationalCipherExample.swift
trackler-2.2.1.144 tracks/swift/exercises/rotational-cipher/Sources/RotationalCipherExample.swift
trackler-2.2.1.143 tracks/swift/exercises/rotational-cipher/Sources/RotationalCipherExample.swift
trackler-2.2.1.142 tracks/swift/exercises/rotational-cipher/Sources/RotationalCipherExample.swift
trackler-2.2.1.141 tracks/swift/exercises/rotational-cipher/Sources/RotationalCipherExample.swift
trackler-2.2.1.140 tracks/swift/exercises/rotational-cipher/Sources/RotationalCipherExample.swift