CTCase
Utility for converting letters to upper/lower case in a constant-time manner (in terms of work performed).
Both CTCase.uppercase and CTCase.lowercase perform the same number of operations no matter the input (i.e. they do not return early).
NOTE: Only characters where Char.isLetter is true are taken from the provided table.
e.g. (NOT constant-time operation)
fun String.containsChar(char: Char): Boolean {
for (c in this) {
if (c == char) return true
}
return false
}
Content copied to clipboard
e.g. (YES constant-time operation)
fun String.containsChar(char: Char): Boolean {
var result = false
for (c in this) {
result = if (c == char) true else result
}
return result
}
Content copied to clipboard
Parameters
table
The decoding table (e.g. ABCDEFGHIJKLMNOPQRSTUVWXYZ234567
)
Throws
IllegalArgumentException
if table contains a letter that has no corresponding lowercase value.