0

Given the following Java code:

import java.math.BigInteger;
import java.util.Base64;
...
String myvar64 = "AQAB";  // assume this is much longer..
byte[] myvarB = Base64.getDecoder().decode(myvar64);
BigInteger myvar = new BigInteger(1, myvarB);

how do you convert the code to python?

I'm assuming the Java code is written that way because Java doesn't have bigint literals (I don't know much java..) If so I'm assuming a simple assignment is sufficient (perhaps with a code comment indicating the original source string):

myvar = 65537  # int("AQAB".decode('base64').encode('hex'), 16)
thebjorn
  • 26,297
  • 11
  • 96
  • 138
  • Possible duplicate of [Convert variable-sized byte array to a integer/long](http://stackoverflow.com/questions/25259947/convert-variable-sized-byte-array-to-a-integer-long) – Joe Sep 22 '16 at 11:19
  • 1
    It's not really a "how do I convert base64 to int in Python" question, but more of a "how do I translate idomatic Java to idiomatic Python for this example". – thebjorn Sep 22 '16 at 11:22
  • @Joe, the comment in front of variable says `assume this is much longer`. in fact OP is trying to convert a BigInteger (assuming a Modulus from RAS Public Key) to Base64 then transfer it to Python and then convert it back to BigInteger then use it as Public Key again. Thus this is not a duplicate of byte array to integer/long – AaA Oct 31 '18 at 06:58
  • @AaA From https://stackoverflow.com/questions/9860588/maximum-value-for-long-integer/9860812, "Long integers have unlimited precision" – Joe Oct 31 '18 at 11:45

0 Answers0