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.78 tracks/swift/exercises/rotational-cipher/Sources/RotationalCipherExample.swift
trackler-2.2.1.77 tracks/swift/exercises/rotational-cipher/Sources/RotationalCipherExample.swift
trackler-2.2.1.76 tracks/swift/exercises/rotational-cipher/Sources/RotationalCipherExample.swift
trackler-2.2.1.75 tracks/swift/exercises/rotational-cipher/Sources/RotationalCipherExample.swift
trackler-2.2.1.74 tracks/swift/exercises/rotational-cipher/Sources/RotationalCipherExample.swift
trackler-2.2.1.73 tracks/swift/exercises/rotational-cipher/Sources/RotationalCipherExample.swift
trackler-2.2.1.72 tracks/swift/exercises/rotational-cipher/Sources/RotationalCipherExample.swift
trackler-2.2.1.71 tracks/swift/exercises/rotational-cipher/Sources/RotationalCipherExample.swift
trackler-2.2.1.70 tracks/swift/exercises/rotational-cipher/Sources/RotationalCipherExample.swift
trackler-2.2.1.69 tracks/swift/exercises/rotational-cipher/Sources/RotationalCipherExample.swift
trackler-2.2.1.68 tracks/swift/exercises/rotational-cipher/Sources/RotationalCipherExample.swift
trackler-2.2.1.67 tracks/swift/exercises/rotational-cipher/Sources/RotationalCipherExample.swift
trackler-2.2.1.66 tracks/swift/exercises/rotational-cipher/Sources/RotationalCipherExample.swift
trackler-2.2.1.65 tracks/swift/exercises/rotational-cipher/Sources/RotationalCipherExample.swift
trackler-2.2.1.64 tracks/swift/exercises/rotational-cipher/Sources/RotationalCipherExample.swift
trackler-2.2.1.63 tracks/swift/exercises/rotational-cipher/Sources/RotationalCipherExample.swift
trackler-2.2.1.62 tracks/swift/exercises/rotational-cipher/Sources/RotationalCipherExample.swift
trackler-2.2.1.61 tracks/swift/exercises/rotational-cipher/Sources/RotationalCipherExample.swift