dsamersoff के उत्तर पर विस्तार करने के लिए .. यह सरल और असुरक्षित है, लेकिन कुछ कार्यों के लिए उपयोगी हो सकता है। यहां कुछ कोड है:
import crypt
import getpass
import os.path
def auth_func():
return (raw_input('Username:'), getpass.getpass('Password:'))
def xor(a,b):
assert len(b) >= len(a)
return "".join([chr(ord(a[i])^ord(b[i])) for i in range(len(a))])
# create a new credentials file if needed
if not os.path.exists('cred'):
with open('cred', 'w') as f:
user, pwd = auth_func()
f.write ("{}\n".format(user))
f.write ("{}\n".format(xor(pwd, crypt.crypt('secret', 'words'))))
f.close()
# read credentials and print user/password
with open('cred', 'r') as f:
user, pwd = f.read().split('\n')[:2]
print user
print xor(pwd, crypt.crypt('secret', 'words'))
स्रोत
2014-06-03 16:58:54
क्या आप पहले से ही * आरएसए * और * पायथन * के लिए googled है? –