-
-
Save icostan/608aa367f83a6ff1c7f8fee3327ce999 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def bytes_to_bignum(bytes_string) | |
bytes_string.bytes.reduce { |n, b| (n << 8) + b } | |
end | |
def bignum_to_bytes(n, length=nil) | |
a = [] | |
while n > 0 | |
a << (n & 0xFF) | |
n >>= 8 | |
end | |
a.fill 0x00, a.length, length - a.length if length | |
a.reverse.pack('C*') | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment