Jump to content

Bitcoin/address validation: Difference between revisions

→‎{{header|Kotlin}}: Updated example see https://github.com/dkandalov/rosettacode-kotlin for details
(→‎{{header|Kotlin}}: Updated example see https://github.com/dkandalov/rosettacode-kotlin for details)
Line 965:
=={{header|Kotlin}}==
{{trans|Java}}
<lang scala>//import version 1java.0security.6MessageDigest
 
import java.security.MessageDigest
 
object Bitcoin {
Line 974 ⟶ 972:
private fun ByteArray.contentEquals(other: ByteArray): Boolean {
if (this.size != other.size) return false
forreturn (i in 0 until this.size).none if{ (this[iit] != other[iit]) return false}
return true
}
 
Line 983 ⟶ 980:
var p = ALPHABET.indexOf(c)
if (p == -1) return null
for (j in 24 downTo 1) {
p += 58 * (output[j].toInt() and 0xff)
output[j] = (p % 256).toByte()
Line 992 ⟶ 989:
return output
}
 
private fun sha256(data: ByteArray, start: Int, len: Int, recursion: Int): ByteArray {
if (recursion == 0) return data
Line 998 ⟶ 995:
md.update(data.sliceArray(start until start + len))
return sha256(md.digest(), 0, 32, recursion - 1)
}
 
fun validateAddress(address: String): Boolean {
if (address.length !in 26..35) return false
val decoded = decodeBase58(address)
if (decoded == null) return false
Cookies help us deliver our services. By using our services, you agree to our use of cookies.