Help Convert Java function to python

whiskey1

Junior Member
Joined
Apr 22, 2015
Messages
109
Reaction score
33
I need help converting java sample code below to python.

Java:
public static String packString(String str) {
    if (TextUtils.isEmpty(str)) {
        return null;
    }
    try {
        byte[] bytes = str.getBytes("UTF-8");
        int length = bytes.length;
        for (int i = 0; i < length; i++) {
            bytes[i] = (byte) (bytes[i] ^ -99);
        }
        return Base64.encodeToString(bytes, 10);
    } catch (Exception unused) {
        return null;
    }
}

Usage:
packString('{"sim_op":"62002","phone_type":1,"net_type":0,"wifi_bssid":"02:00:00:00:00:00"}')
return value: 5r_u9PDC8u2_p7-rr62tr7-xv-318vP4wunk7fi_p6yxv_P46cLp5O34v6etsb_q9Pv0wv_u7vT5v6e_ra-nra2nra2nra2nra2nra2_4A==
 
Back
Top