Created
March 18, 2010 13:16
-
-
Save rowlandwatkins/336331 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
Here's my problem: I have a Base64 encoded prime number (128 bytes): | |
C# Base64 encoded byte[]: | |
0hro1m5sazztDrPfGibJG97tATwX2EnTDsMJgT5NN5nybbDUlOguxh6p/ccLtcvK8uXxioNklPWOZ8bWFkgMN6fyMGEB/J8PR2j5yXk8K+F2sLfJebQGXT6DVoaj8LhCDGg0yxeTA4be2rKwfdRzRJpIuqsxYoa0IQUkddE0zTs= | |
Java Base64 encoded byte[]: | |
ANIa6NZubGs87Q6z3xomyRve7QE8F9hJ0w7DCYE+TTeZ8m2w1JToLsYeqf3HC7XLyvLl8YqDZJT1jmfG1hZIDDen8jBhAfyfD0do+cl5PCvhdrC3yXm0Bl0+g1aGo/C4QgxoNMsXkwOG3tqysH3Uc0SaSLqrMWKGtCEFJHXRNM07 | |
Note that the above encodings represent the following big integer: | |
147540829457233765072451123330814771849279870508740658191364766390571127595133276091294946062334381927384270351919254939797952329145575009188956176344993292905052474988906261438800251337646245695529118629813762877963253295780055957721171296243452181910303437299543284160580397044072404446659484077705433238843 | |
In Java I can get the correct BigInteger by ensuring the signum is set to 1 in the constructor after decoding the Base64 representation: | |
BigInteger bob = new BigInteger(1, decoded) | |
C# requires you to change the byte order to big endian then stick in a BitInteger. | |
Creating a Bignum representation in Ruby is being a pain as a result (I think): | |
bites = Base64.decode64 value | |
res = bites.unpack("L*") | |
puts res | |
Output (C# Base64 encoded bytep[]): | |
35249789021852599100397716374343874946737400743004000506432476629771045247897406727496424982442945144570311964635624075155850220440702923891657823738204712817667169333330071198062025203398652919912928732041841245104879475827504620182081558513955106623738874544211107514025884576438285405965539851413509898555 | |
Output (Java Base64 encoded byte[]): | |
137694483597560939102216875537430330334675944971008195657354096000921683438632582801840356652855833238983653339433419340491620923238667724119750598359178446093375339216275201592563381693380165675378265208733801963581564377942225889093611081093643407319811226275192229610364031150961850287214042230220628841976644813 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment