how can I best translate this java method to python
<p>how can i write less python2 code to achieve the same thingï¼need encryption results are the same.</p>

<p><code>b[i++] = (byte) 172;</code> In what way cast int to byte  in python2....</p>

<pre><code>public static String encryptPassword(String content) {


    String resultString = "";
       String appkey = "ftjf,ckdfkl";

       byte[] a = appkey.getBytes();
       byte[] datSource = content.getBytes();
       byte[] b = new byte[a.length + 4 + datSource.length];

       int i;
    for (i = 0; i &lt; datSource.length; i++) {
        b[i] = datSource[i];
    }

    b[i++] = (byte) 172;
    b[i++] = (byte) 163;
    b[i++] = (byte) 161;
    b[i++] = (byte) 163;

    for (int k = 0; k &lt; a.length; k++) {
        b[i] = a[k];
        i++;
    }

    try {
        MessageDigest md5 = MessageDigest.getInstance("MD5");
        md5.update(b);
        resultString = new HexBinaryAdapter().marshal(md5.digest());
    } catch (Exception e) {

    }

    return resultString.toLowerCase();
}


public static void main(String[] args) {
    System.out.print(encryptPassword("123456"));
}
</code></pre>

<p>Use <code>chr</code> to get the char of a byte in python.</p>

<pre><code>from Crypto.Hash import MD5

key = 'ftjf,ckdfkl'
src= '123'
b = src+chr(172)+chr(163)+chr(161)+chr(163)+key
md5 = MD5.new()
md5.update(b)
text = md5.hexdigest()
print text
</code></pre>

<p>Given the src '123',output is:</p>

<pre><code>eedb36cc3204923459dcf891224a0c1d
</code></pre>

java python python-2.7 python-3.x