mirror of
https://github.com/KyleBanks/XOREncryption.git
synced 2023-08-10 21:13:15 +03:00
commit
85d0688955
20
Kotlin/XOREncryption.kt
Normal file
20
Kotlin/XOREncryption.kt
Normal 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
|
||||||
|
}
|
@ -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)
|
||||||
|
Loading…
Reference in New Issue
Block a user