package com.peachpasswords.sync object SASDerivation { fun derive(handshakeHash: ByteArray): String { require(handshakeHash.size >= 4) { "Handshake hash too short" } val n = (((handshakeHash[0].toInt() and 0xFF) shl 24) or ((handshakeHash[1].toInt() and 0xFF) shl 16) or ((handshakeHash[2].toInt() and 0xFF) shl 8) or (handshakeHash[3].toInt() and 0xFF)).toLong() and 0xFFFFFFFFL return (n % 1_000_000L).toString().padStart(6, '0') } }