Use Python to encrypt your password

Source: Internet
Author: User
Sometimes we have to write passwords in our own code, for security reasons, we can encrypt our own passwords.

First the code, this code is transferred from the Internet

root@proftp:/usr/lib/python2.7# more jastmencrypt.py "" "Jastme Encrypt Password" "Def encrypt (key, s):   B = ByteArray (str (s). Encode ("GBK"))   n = len (b) # to find the number of bytes of b   C = ByteArray (n*2)   j = 0 for   i in range (0, N):     B1 = b[i]     b2 = b1 ^ Key # B1 = b2^ key     c1 = b2%     c2 = b2//# B2 = c2*16 + C1     C1 = c1 + + C2     = C2 + # C1,C2 are all the numbers between 0~15, plus 65 becomes the encoding of the a-p character     c[j] = C1     c[j+1] = C2     j = j+2   return c.decode ("GBK") 
  def decrypt (key, s):   c = ByteArray (str (s). Encode ("GBK"))   n = Len (c) # Calculates the number of bytes of B   if n% 2! = 0:     retu  RN ""   n = n//2   B = ByteArray (n)   j = 0   for i in range (0, N):     c1 = c[j]     c2 = c[j+1]     j = j+2     c1 = c1-65     c2 = c2-65     b2 = c2*16 + C1     b1 = b2^ key     b[i]= B1   try:     return B.deco De ("GBK")   except:     return "Failed"

Save this code with UTF8 encoding to/usr/lib/python2.7

In [1]: Import Jastmencrypt in [3]: Jastmencrypt.encrypt (119, ' MyPassword ')        encryption out[3]: U ' kboahagbeaeaaaibfadb ' in [4] : Jastmencrypt.decrypt (119, ' kboahagbeaeaaaibfadb ')   decryption out[4]: U ' mypassword '

We encrypt the password in the Ipython first, and then get the code, to use the time to decrypt it, which can be a great guarantee of our password security.

The above is to share all the content of this article, I hope that you learn Python code can be helpful.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.