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.