From 89c46dc59c58dfbd9fb654b8acf6d984f2c877b3 Mon Sep 17 00:00:00 2001 From: Oguz Date: Sun, 7 Jan 2018 23:30:44 +0300 Subject: [PATCH] add Kotlin support --- Kotlin/XOREncryption.kt | 20 ++++++++++++++++++++ README.md | 1 + 2 files changed, 21 insertions(+) create mode 100644 Kotlin/XOREncryption.kt diff --git a/Kotlin/XOREncryption.kt b/Kotlin/XOREncryption.kt new file mode 100644 index 0000000..abfc8f0 --- /dev/null +++ b/Kotlin/XOREncryption.kt @@ -0,0 +1,20 @@ +fun encryptDecrypt(input: String): String { + val key = charArrayOf('K', 'C', 'Q') //Can be any chars, and any length array + val output = StringBuilder() + + for (i in 0 until input.length) { + val a: Int = input[i].toInt() + val b: Int = key[i % key.size].toInt() + output.append((a xor b).toChar()) + } + + return output.toString() +} + +fun main(args: Array) { + val encrypted = encryptDecrypt("kylewbanks.com") + println("Encrypted: $encrypted") // output: Encrypted: :=.43*-:8m2$. + + val decrypted = encryptDecrypt(encrypted) + println("Decrypted: $decrypted") // output: Decrypted: kylewbanks.com +} \ No newline at end of file diff --git a/README.md b/README.md index d350a21..12f88cd 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,7 @@ Simple implementation of XOR Encryption/Decrypting in various languages, includi - [Groovy](Groovy/XOREncryption.groovy) - [Java \(Android Compatible\)](Java \(Android compatible\)/XOREncryption.java) - [JavaScript \(Node.js Compatible\)](JavaScript/XOREncryption.js) +- [Kotlin](Kotlin/XOREncryption.kt) - [Objective-C](Objective-C/main.m) - [Python](Python/XOREncryption.py) - [Ruby](Ruby/xor.rb)