Jump to content

Playfair cipher: Difference between revisions

(Added Kotlin)
Line 878:
}
 
class Playfair(val keyword: String, val pfo: PlayfairOption) {
private val table: Array<CharArray> = Array(5, { CharArray(5) }) // 5 x 5 char array
 
Line 943:
}
 
public fun encode(plainText: String): String {
val cleanText = getCleanText(plainText)
var cipherText = ""
varval length = cleanText.length
for (i in 0 until length step 2) {
val (row1, col1) = findChar(cleanText[i])
Line 960:
}
 
public fun decode(cipherText: String): String {
var decodedText = ""
varval length = cipherText.length
for (i in 0 until length step 3) { // cipherText will include spaces so we need to skip them
val (row1, col1) = findChar(cipherText[i])
Line 971:
else -> table[row1][col2].toString() + table[row2][col1]
}
if (i < length - 1) decodedText += " "
}
return decodedText
}
 
public fun printTable() {
println("The table to be used is :\n")
for (i in 0..4) {
Cookies help us deliver our services. By using our services, you agree to our use of cookies.