Sha256: 9632b8b098860d9f04c6193815d4a76babc6360432758c87c7c6119413659162

Contents?: true

Size: 788 Bytes

Versions: 48

Compression:

Stored size: 788 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

48 entries across 48 versions & 1 rubygems

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