add Kotlin support

This commit is contained in:
Oguz 2018-01-07 23:30:44 +03:00
parent 2e562345ac
commit 89c46dc59c
2 changed files with 21 additions and 0 deletions

20
Kotlin/XOREncryption.kt Normal file
View File

@ -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<String>) {
val encrypted = encryptDecrypt("kylewbanks.com")
println("Encrypted: $encrypted") // output: Encrypted: :=.43*-:8m2$.
val decrypted = encryptDecrypt(encrypted)
println("Decrypted: $decrypted") // output: Decrypted: kylewbanks.com
}

View File

@ -12,6 +12,7 @@ Simple implementation of XOR Encryption/Decrypting in various languages, includi
- [Groovy](Groovy/XOREncryption.groovy) - [Groovy](Groovy/XOREncryption.groovy)
- [Java \(Android Compatible\)](Java \(Android compatible\)/XOREncryption.java) - [Java \(Android Compatible\)](Java \(Android compatible\)/XOREncryption.java)
- [JavaScript \(Node.js Compatible\)](JavaScript/XOREncryption.js) - [JavaScript \(Node.js Compatible\)](JavaScript/XOREncryption.js)
- [Kotlin](Kotlin/XOREncryption.kt)
- [Objective-C](Objective-C/main.m) - [Objective-C](Objective-C/main.m)
- [Python](Python/XOREncryption.py) - [Python](Python/XOREncryption.py)
- [Ruby](Ruby/xor.rb) - [Ruby](Ruby/xor.rb)