Sample code for 30+ languages & platforms
Swift

Obfuscate String

Demonstrates how to obfuscate and unobfuscate a string.

Chilkat Swift Downloads

Swift

func chilkatTest() {
    var success: Bool = false

    let sb = CkoStringBuilder()!

    var s: String? = "Hello World!"

    sb.append(value: s)
    print("\(sb.getAsString()!)")

    // Output is "Hello World!";

    // Obfuscate the string.
    // This is NOT encryption.  It's just a simple obfuscation.
    sb.obfuscate()
    print("\(sb.getAsString()!)")

    // Output is 2GsgGhbSQVyG8Vb9

    // -------------------------
    // Unobfuscate.
    let sb2 = CkoStringBuilder()!
    var s2: String? = "2GsgGhbSQVyG8Vb9"
    sb2.append(value: s2)
    sb2.unobfuscate()

    print("\(sb2.getAsString()!)")

    // Output is "Hello World!";

}