Merge pull request #13 from arcv/master

add Kotlin support
This commit is contained in:
Kyle Banks 2018-01-08 07:08:14 -05:00 committed by GitHub
commit 85d0688955
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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)