How can I convert this Java encryption code to python
The bug in the Python code is in the concatenation, it must be:
base64ed = base64.b64encode(cipher.nonce + ciphertext + tag).decode('utf-8')
After this fix, if you compare the ciphertexts of both codes with identical input data (especially with identical IV), they are the same.
how can I translate efficiently a Java code to python?
If you want to translate java code to python you have to translate it manually. Automatic conversion generally does not have the appropriate quality. It looks like there are some tools out e.g. java2python but the author states
The generated Python code is not guaranteed to run, nor is guaranteed to be syntactically valid Python.
Converting a library to another programming language is never an easy task.
If you simply want to use a java library in a application that you want to write in python you could give jython a try.
Parsing string long to int with java and python
In the end, I used the answer from gengkev here.
By playing around, I found something similar to BreizhGatch's function, but that doesn't require a conditional statement. n & 0x80000000 extracts the 32-bit sign bit; then, the - keeps the same 32-bit representation but sign-extends it; finally, the extended sign bits are set on n.
n = n & 0xffffffff
return n | (-(n & 0x80000000))
How to convert Java datetime code to Python
You have to install
pytz (a World Timezone Definitions package) on your system.
Try this :
from datetime import datetime
from pytz import timezone
now = datatime.datetime.now();
gmt_time = now.replace(tzinfo=timezone('GMT'))
print(gmt_time.strftime("%a, %d %b %Y %H:%M:%S %z"))
I have referred from here (this includes the installation process) : http://pytz.sourceforge.net/#tzinfo-api
Reverse a String Without Affecting Special Characters
How to Remove Trailing Zeros from a Double
Jpa- Joining Two Tables in Non-Entity Class
Could Not Read Json: Can Not Deserialize Instance of Hello.Country Out of Start_Object Token
Maven Build Cannot Find Symbol When Accessing Project Lombok Annotated Methods,
In Java, How to Determine If a Char Array Contains a Particular Character
Retrieving Data from Biometric Fingerprint Attendance Device
Regular Expression for Excluding Special Characters
How to Have Each Record of Json on a Separate Line
Flush/Clear System.In (Stdin) Before Reading
Use String.Split() With Multiple Delimiters
How to Use Jackson to Deserialise an Array of Objects
Gradle: How to Exclude a Particular Package from a Jar
How to Solve Error: Could Not Find Method Onclick(View) in a Parent or Ancestor Context for Android:Onclick
How to Increase the Java Heap Size Permanently
How to Get Numbers from Given Gcd and Lcm
How to Download Entire Folder Located on S3 Bucket
Jackson @Jsonproperty Not Working If Property Name Not Equal Field Name