Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8778697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:35:40+00:00 2026-06-13T19:35:40+00:00

I’m working on a server application in Python and an app to connect to

  • 0

I’m working on a server application in Python and an app to connect to it in Java. I need to encrypt the string in Java and then decrypt it in Python.

Everything works well with the Java code, but there is a problem with the Python code.

from Crypto.Cipher import AES
obj        = AES.new('0123456789abcdef', AES.MODE_CBC,IV="fedcba9876543210")
BLOCK_SIZE = 16
PADDING    = " "
pad        = lambda s: s + (BLOCK_SIZE - len(s) % BLOCK_SIZE) * PADDING
plain      = "password"
plain      = pad (plain)
ciph       = obj.encrypt(plain)
obj        = AES.new('0123456789abcdef', AES.MODE_CBC,IV="fedcba9876543210")
decrypted  = obj.decrypt(ciph)
result     = ""
for char in ciph:
    result += str((hex(ord(char))))[2:]
print result
print decrypted

The results of this are:

2af41fc02b33765b56433f59edb67dd3
password

Which is what I would expect and matches the Java output, however when I plug in the first of the 2 lines to decrypt it in the Python code, the output is totally off and displays random characters. I think that is due to the for loop at the end which makes it the same as the Java output. Is there a way to undo that for loop? Also using code at least similar to this is there a decent way to decrypt the first of the two output strings (in Python)?

I appreciate all responses, thank you ahead of time!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T19:35:41+00:00Added an answer on June 13, 2026 at 7:35 pm

    Every pair of digits in result is the character code of a char in hexadecimal. Here’s a snippet that reproduces the transformation and undoes it (there are more elegant ways to do this, but it’s simple and it works).

    import re
    
    ciph = "hello there"
    result = ""
    for c in ciph:
        result += str((hex(ord(c))))[2:]
    
    # reverse it
    orig = ""
    for code in re.findall('..', result):
        orig += chr(int(code, 16))
    print orig  # "hello there"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have thousands of HTML files to process using Groovy/Java and I need to
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
Specifically, suppose I start with the string string =hello \'i am \' me And
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I would like to count the length of a string with PHP. The string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.