From 51b1a6769a9932db63fbda261e230dcbd9df3aba Mon Sep 17 00:00:00 2001 From: Janis Erdmanis Date: Wed, 30 Oct 2024 22:44:24 +0200 Subject: [PATCH] fixing bitlength at zero --- Project.toml | 2 +- src/CryptoPRG.jl | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 764a7d6..380b472 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "CryptoPRG" uuid = "d846c407-34c1-46cb-aa27-d51818cc05e2" authors = ["Janis Erdmanis "] -version = "0.1.1" +version = "0.1.2" [deps] Nettle = "49dea1ee-f6fa-5aa6-9a11-8816cee7d4b9" diff --git a/src/CryptoPRG.jl b/src/CryptoPRG.jl index a4dff2e..75094a9 100644 --- a/src/CryptoPRG.jl +++ b/src/CryptoPRG.jl @@ -37,6 +37,10 @@ end function bitlength(p::BigInt) + if p == 0 + return 1 + end + # A dublicate is in CryptoGroups # It is an implementation detail within the context of package function _int2bytes(x::Integer) @@ -51,6 +55,7 @@ function bitlength(p::BigInt) bytes = _int2bytes(p) bits = bitstring(bytes[end]) start = findfirst(x -> x == '1', bits) + N = length(bytes) * 8 - (start - 1) return N