Share a Python username and password to log in to the system
# -*- coding: gb2312 -*-#用户名密码登录系统(MD5加密并存入文件)及对字符串进行凯撒密码加解密操作#作者:凯鲁嘎吉 - 博客园 import hashlibdef md5(arg):#这是加密函数,将传进来的函数加密md5_pwd = hashlib.md5(bytes('admin')) md5_pwd.update(bytes(arg))return md5_pwd.hexdigest()#返回加密的数据def log(user,pwd):#登录时的函数,由于md5不能反解,因此登陆的时候用正解with open('pass.txt','r') as f:for line in f: u,p=line.strip().split('|')if u == user and p == md5(pwd):#登录的时候验证用户名以及加密的密码跟之前保存的是否一样 return Truedef register(user,pwd):#注册的时候把用户名和加密的密码写进文件,保存起来with open('pass.txt','a') as f: temp = user+'|'+ md5(pwd)+'\n'f.write(temp)def encryption(): #加解密界面offset=int(input('~~~~~~~~~~~~~~~~~~~~~~~~~~\n' '请输入偏移量:\n' '大于0小于26:偏移量\n' '0:退出登录\n' '~~~~~~~~~~~~~~~~~~~~~~~~~~\n'))if offset in range(1,25): variable=int(input('~~~~~~~~~~~~~~~~~~~~~~~~~~\n' '请选择操作:\n' '1:加密\n' '2:解密\n' '~~~~~~~~~~~~~~~~~~~~~~~~~~\n')) user1=Caesar(offset,variable) user1.choose()elif offset==0:print('谢谢使用,再见!') exit(0)else:print('偏移量超出范围,请重新输入!')class Caesar: # 定义类,名叫Caesardef __init__(self, offset, variable):# 初始化self.passage = offset self.type = variabledef encrypt(self,offset): # 加密move = (ord(offset)-97+self.passage) % 26+97 # 用ASCII码值来完成移动,ord()将字符转化为对应ASCII码的十进制数return chr(move) #将ASCII码转化为对应的数值,chr()将一个整数转化为Unicode字符def decrypt(self,offset): # 解密move=(ord(offset)-97-self.passage)%26+97if move
Result:
C:\Python27\python.exe D:/Mypython/Myexercise/_kaisa_passage.py~~~~~~~~趣味密码学~~~~~~~0.退出1.登录2.注册~~~~~~~~~~~~~~~~~~~~~~~~请输入您的选择:2用户名('xxx'):'wrr'密码('xxx'):'123'~~~~~~~~趣味密码学~~~~~~~0.退出1.登录2.注册~~~~~~~~~~~~~~~~~~~~~~~~请输入您的选择:2用户名('xxx'):'123'密码('xxx'):'123456'~~~~~~~~趣味密码学~~~~~~~0.退出1.登录2.注册~~~~~~~~~~~~~~~~~~~~~~~~请输入您的选择:1用户名('xxx'):'123'密码('xxx'):'123456'登录成功~~~~~~~~~~~~~~~~~~~~~~~~~~请输入偏移量: 大于0小于26:偏移量 0:退出登录~~~~~~~~~~~~~~~~~~~~~~~~~~ 3 ~~~~~~~~~~~~~~~~~~~~~~~~~~请选择操作:1:加密2:解密~~~~~~~~~~~~~~~~~~~~~~~~~~ 1请输入要加密的字符串('xxx'):'qwert'字符串qwert加密后为:tzhuw~~~~~~~~~~~~~~~~~~~~~~~~~~请输入偏移量: 大于0小于26:偏移量 0:退出登录~~~~~~~~~~~~~~~~~~~~~~~~~~ 3 ~~~~~~~~~~~~~~~~~~~~~~~~~~请选择操作:1:加密2:解密~~~~~~~~~~~~~~~~~~~~~~~~~~ 2请输入要解密的字符串('xxx'):'tzhuw'字符串tzhuw解密后为:qwert~~~~~~~~~~~~~~~~~~~~~~~~~~请输入偏移量: 大于0小于26:偏移量 0:退出登录~~~~~~~~~~~~~~~~~~~~~~~~~~0 谢谢使用,再见! Process finished with exit code 0
Or:
C:\Python27\python.exe D:/Mypython/Myexercise/_kaisa_passage.py~~~~~~~~趣味密码学~~~~~~~0.退出1.登录2.注册~~~~~~~~~~~~~~~~~~~~~~~~请输入您的选择:1用户名('xxx'):'wrr'密码('xxx'):'123'登录成功~~~~~~~~~~~~~~~~~~~~~~~~~~请输入偏移量: 大于0小于26:偏移量 0:退出登录~~~~~~~~~~~~~~~~~~~~~~~~~~0 谢谢使用,再见! Process finished with exit code 0
Or:
C:\Python27\python.exe D:/Mypython/Myexercise/_kaisa_passage.py~~~~~~~~趣味密码学~~~~~~~0.退出1.登录2.注册~~~~~~~~~~~~~~~~~~~~~~~~请输入您的选择:1用户名('xxx'):'123'密码('xxx'):'456'登录失败 还有2次尝试机会! 用户名('xxx'):'456'密码('xxx'):'485'登录失败 还有1次尝试机会! 用户名('xxx'):'425'密码('xxx'):'425552'登录失败 密码输入次数过多,账户将被锁定! Process finished with exit code 0
The pass.txt file save result is as follows:
The above is the detailed content of Share a Python username and password to log in to the system. For more information, please follow other related articles on the PHP Chinese website!

Python excels in gaming and GUI development. 1) Game development uses Pygame, providing drawing, audio and other functions, which are suitable for creating 2D games. 2) GUI development can choose Tkinter or PyQt. Tkinter is simple and easy to use, PyQt has rich functions and is suitable for professional development.

Python is suitable for data science, web development and automation tasks, while C is suitable for system programming, game development and embedded systems. Python is known for its simplicity and powerful ecosystem, while C is known for its high performance and underlying control capabilities.

You can learn basic programming concepts and skills of Python within 2 hours. 1. Learn variables and data types, 2. Master control flow (conditional statements and loops), 3. Understand the definition and use of functions, 4. Quickly get started with Python programming through simple examples and code snippets.

Python is widely used in the fields of web development, data science, machine learning, automation and scripting. 1) In web development, Django and Flask frameworks simplify the development process. 2) In the fields of data science and machine learning, NumPy, Pandas, Scikit-learn and TensorFlow libraries provide strong support. 3) In terms of automation and scripting, Python is suitable for tasks such as automated testing and system management.

You can learn the basics of Python within two hours. 1. Learn variables and data types, 2. Master control structures such as if statements and loops, 3. Understand the definition and use of functions. These will help you start writing simple Python programs.

How to teach computer novice programming basics within 10 hours? If you only have 10 hours to teach computer novice some programming knowledge, what would you choose to teach...

How to avoid being detected when using FiddlerEverywhere for man-in-the-middle readings When you use FiddlerEverywhere...

Error loading Pickle file in Python 3.6 environment: ModuleNotFoundError:Nomodulenamed...


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SublimeText3 Chinese version
Chinese version, very easy to use

WebStorm Mac version
Useful JavaScript development tools

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft