Compare commits

..

4 Commits

Author SHA1 Message Date
12ba3bf530 Update README.md 2026-04-16 16:12:39 +00:00
b2d8048713 Upgrade plugin 2026-02-15 14:10:59 +01:00
c366c79d4c refactor utility function name 2026-02-03 23:03:59 +01:00
e08cbb0fa9 fix README
All checks were successful
/ test (pull_request) Successful in 45s
2026-01-21 22:09:31 +01:00
5 changed files with 16 additions and 12 deletions

View File

@@ -1,15 +1,19 @@
# encoding-kt
# encoding.kt
`encoding-kt` is a Kotlin Multiplatform library that provides common `ByteArray` encodings.
`encoding.kt` is a Kotlin Multiplatform library that provides common `ByteArray` encodings.
Supported encodings:
- Base2 (binary)
- Base8 (octal)
- Base16 (hexadecimal)
- Base10 (decimal)
- Base16 (hexadecimal, uppercase/lowercase)
- Base32
- Base36
- Base45
- Base56
- Base58
- Base62
- Base64
- Base64 (standard/URL)
## Installation
@@ -35,6 +39,6 @@ fun main() {
// encode the string with the desired encoding
val encoded = Base16.encode(test).decodeToString()
println(encoded) // 48656c6c6f20576f726c6421
println(encoded) // 48656C6C6F20576F726C6421
}
```

View File

@@ -1,5 +1,5 @@
[versions]
infendro = "1.0.0"
infendro = "1.1.0"
kotlin = "2.3.0"
[plugins]

View File

@@ -2,7 +2,7 @@ package com.infendro.encoding
import com.infendro.encoding.exception.IllegalByteException
import com.infendro.encoding.util.align
import com.infendro.encoding.util.divCeil
import com.infendro.encoding.util.ceilDiv
import com.infendro.encoding.util.lcm
import com.infendro.encoding.util.log2
@@ -17,8 +17,8 @@ class StreamEncoding internal constructor(
override fun encode(bytes: ByteArray): ByteArray {
val size = when (padding) {
null -> (bytes.size * 8).divCeil(bits)
else -> (bytes.size * 8).divCeil(bits).align(block)
null -> (bytes.size * 8).ceilDiv(bits)
else -> (bytes.size * 8).ceilDiv(bits).align(block)
}
val encoded = ByteArray(size)
var i = 0

View File

@@ -62,7 +62,7 @@ internal class BigInt private constructor(
get() = BigInt(intArrayOf(0))
fun from(bytes: ByteArray): BigInt {
val words = IntArray(bytes.size.divCeil(4))
val words = IntArray(bytes.size.ceilDiv(4))
for (i in bytes.indices) {
val (wi, bi) = (bytes.lastIndex - i).divRem(4)
words[wi] = words[wi] or ((bytes[i].toInt() and 0xFF) shl (bi * 8))

View File

@@ -2,11 +2,11 @@ package com.infendro.encoding.util
import kotlin.math.log2
internal fun Int.divCeil(n: Int): Int =
internal fun Int.ceilDiv(n: Int): Int =
(this + n - 1) / n
internal fun Int.align(n: Int): Int =
divCeil(n) * n
ceilDiv(n) * n
internal fun log2(value: Int): Double =
log2(value.toDouble())