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

  • SEARCH
  • Home
  • 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 8108893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T01:15:07+00:00 2026-06-06T01:15:07+00:00

I am using Python 2.7 . I have an alphanumeric string, on which I

  • 0

I am using Python 2.7. I have an alphanumeric string, on which I want to perform a encryption/decryption. Whatever I do should remain 2-way and the result should be alphanumeric too.

For example:

str = 'ma6546fbd'
encrypted_data = encrypt_function(str)
decrypted_data = decrypt_function(encrypted_data)
print decrypted_data # I get 'ma6546fbd'

What have I done:

I have written a function

def xor_crypt_string(data, key):
    return ''.join(chr(ord(x) ^ ord(y)) for (x,y) in izip(data, cycle(key)))

This takes the data and a key and returns the result, the problem is that it includes special characters too, which I want to avoid.

  • 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-06T01:15:09+00:00Added an answer on June 6, 2026 at 1:15 am

    If you want serious encryption (read unbreakable) then I’d use AES from pycrypto something like this.

    >>> from Crypto.Cipher import AES
    >>> from Crypto import Random
    >>> key = b'Sixteen byte key'
    >>> iv = Random.new().read(AES.block_size)
    >>> cipher = AES.new(key, AES.MODE_CFB, iv)
    >>> msg = iv + cipher.encrypt(b'Attack at dawn')
    >>> msg.encode("hex")
    'e10e096aabff9db382abe8d704404995a7b64d72a4e1b9e5208912d206c4'
    

    That is your ascii message. Now decode the message like this

    >>> recv='e10e096aabff9db382abe8d704404995a7b64d72a4e1b9e5208912d206c4'
    >>> cipher.decrypt(recv.decode("hex"))[len(iv):]
    'Attack at dawn'
    >>> 
    

    Any encryption method you make up yourself will be easily breakable by an expert and the one you’ve shown above falls into that category.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a python logger set up, using python's logging module. I want to
Does Python have a built-in, simple way of encoding/decoding strings using a password? Something
I'm using Python, and I have a file which has city names and information
I'm using python and I have to login at some site, which asks for
I have a python script which I call using python main.py on my terminal.
I'm looking for a way to fully qualify a URL using Python. I have
I'm using Python and I have some data that I want to put into
I just started using/learning Python and have some questions. I have a text file
I am new to selenium and I am using python but I have a
I have a working application using python and zeromq and I would like to

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.