Skip to content

Instantly share code, notes, and snippets.

@hamnis
Created January 23, 2025 17:58
Show Gist options
  • Save hamnis/a09e71c0788a97bc5cdd987d3b831ea1 to your computer and use it in GitHub Desktop.
Save hamnis/a09e71c0788a97bc5cdd987d3b831ea1 to your computer and use it in GitHub Desktop.
import scodec.bits.*
object Math {
def extractN(x: BigInt, alphabet: Int, n: Int): String = {
val array = new Array[Int](n)
(0 until n).foldLeft(x)((agg, idx) => {
val (next, rem) = agg /% alphabet
array(idx) = rem.toInt
next
})
array.mkString
}
def extractNDigits(vec: ByteVector, n: Int) = extractN(BigInt(vec.sha1.toHex, 16), 10, n)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment