'''

作业:中英文加密+解密

做题思路:先练习单独用ascii和汉字加密和解密,见作业后的encode_game和decode_game

爬取中文用的是BeautifulSoup

作业encode_hw和decode_hw基于前面的练习进行整合

'''

import requests

from bs4 import BeautifulSoup

def get_hans(url):

res = requests.get(url)

soup = BeautifulSoup(res.text, 'html.parser')

item = soup.find_all('div', class_='bs_index3')

for i in item:

hans_list0 = i.find_all('li')

for j in hans_list0:

hans = j.text

hans_list.append(hans)

url = 'http://www.zdic.net/zd/zb/cc1'

hans_list = []

get_hans(url)

# 中英文加密

def encode_hw():

code_input = input('>>>>')

encode_input = ''

for tag_encode in code_input:

i_analy = ord(tag_encode)

if 64 < i_analy < 78 or 96 < i_analy < 110:

encode_input += chr(i_analy + 13)+ '|'

elif 77 < i_analy < 91 or 109 < i_analy < 123:

encode_input += chr(i_analy - 13)+ '|'

elif i_analy >= 128:

for index, element in enumerate(hans_list):

if tag_encode == element:

encode_input += str(index) + '|'

else:

encode_input += tag_encode

return encode_input

ret = encode_hw()

print('加密后的是:'+ret)

# 中英文解密

def decode_hw():

decode_input = ''

code_input = input('>>>>')

res = code_input.split('|')

for item in res:

if item.isalpha():

for item_ele in item:

j_analy = ord(item_ele)

if 64 < j_analy < 78 or 96 < j_analy < 110:

decode_input += chr(j_analy + 13)

elif 77 < j_analy < 91 or 109 < j_analy < 123:

decode_input += chr(j_analy - 13)

elif item.isdigit():

index_int = int(item)

decode_input += hans_list[index_int]

else:

decode_input += item

return decode_input

print('解密后的是:'+decode_hw())

# ASCII加密

# def encode_game():

# code_input = input('>>>>')

# encode_input = ''

# for i in code_input:

# i_analy = ord(i)

# if 64 < i_analy < 78 or 96 < i_analy < 110:

# encode_input += chr(i_analy + 13)

# elif 77 < i_analy < 91 or 110 < i_analy < 123:

# encode_input += chr(i_analy - 13)

# else:

# encode_input += i

# return encode_input

# print('加密后的是:'+encode_game())

#

# # ASCII解密

# def decode_game():

# code_input = input('>>>>')

# decode_input = ''

# for j in code_input:

# j_analy = ord(j)

# if 64 < j_analy < 78 or 96 < j_analy < 110:

# decode_input += chr(j_analy + 13)

# elif 77 < j_analy < 91 or 109 < j_analy < 123:

# decode_input += chr(j_analy - 13)

# else:

# decode_input += j

# return decode_input

# print('解密后的是:'+decode_game())

# 汉字加密

#

# import requests

# from bs4 import BeautifulSoup

# def get_hans(url):

# res = requests.get(url)

# soup = BeautifulSoup(res.text,'html.parser')

# item = soup.find_all('div',class_='bs_index3')

# for i in item:

# hans_list0 = i.find_all('li')

# for j in hans_list0:

# hans = j.text

# hans_list.append(hans)

# url = 'http://www.zdic.net/zd/zb/cc1'

# hans_list = []

# get_hans(url)

# # # print(len(hans_list))

# # 中文加密

# def encode_game():

# encode_input = input('>>>>')

# code_analy = ''

# for hans_input in encode_input:

# for index, element in enumerate(hans_list):

# if hans_input == element:

# code_analy += str(index) + '|'

#

# return code_analy

# ret = encode_game()

# print('加密后:'+ret)

#

# #中文解密

# decode_analy = ''

# res = ret.split('|')

# res.remove('')

# # for index in res:

# print(res)

# for i in res:

# index_int = int(i)

# decode_analy += hans_list[index_int]

# print('解密后:'+decode_analy)

python代码加密解密_Python加密解密代码相关推荐

  1. python 加密库_Python加密库入门

    python 加密库 密码学俱乐部的第一条规则是:永远不要自己发明密码系统. 密码学俱乐部的第二条规则是:永远不要自己实施密码系统:在密码系统的实施阶段以及设计中都会发现许多现实世界的漏洞. 一个有用 ...

  2. python代码代写_python代写代码

    广告关闭 腾讯云11.11云上盛惠 ,精选热门产品助力上云,云服务器首年88元起,买的越多返的越多,最高返5000元! 1 原则在开始讨论python社区所采用的具体标准或是由其他人推荐的建议之前,考 ...

  3. python中文版加密解密_python加密与解密

    你有很多重复的代码...我们来解决这个问题..在 首先只为Caesar密码定义2个函数.一个用于加密和解密字符,另一个用于整个字符串.在 正数shift是加密,负数shift是解密.在def ciph ...

  4. python 加密解密_python加密解密

    EncodeFile(python2.7 加密 ) # -*- coding: utf8 -*- import base64 import sys reload(sys) sys.setdefault ...

  5. python加密与解密_Python加密与解密,pythonCrypt,和

    from Crypto.Cipher import AES class DeAesCrypt: """ AES-128-CBC 加/解密, Padding ZERO模式 ...

  6. python hashlib解密_python 加密解密

    MD5 import hashlib c = raw_input('输入字符:') #python3为input b = hashlib.md5() b.update(c.encode(encodin ...

  7. python加密包_python加密包利用pycrypto包进行AES、DES、MD5等加密

    第三方Crypto包提供了较全面的加密算法,包括Cipher.Hash.Protocol.PublicKey.Singature.Util几个子模块,其中Cipher模块中有常用的AES.DES加密算 ...

  8. python的pyd文件_Python 加密之 生成pyd文件

    混淆代码,我准备使用pyminifier.而加密处理,就比较麻烦. Python有py.pyc.pyw.pyo.pyd等文件格式. 其中,pyc是二进制文件.但很容易被反编译. pyw也不行,只是隐藏 ...

  9. python等号语法错误_Python干货:代码编写规范

    本章节我们来讲述一下Python的编码规范,通过详细对代码编写规则以及命名规范等进行介绍. 1.编写规则 Python采用PEP 8 的编码规范,接下来会讲解一些我们在学习Python过程应该严格遵守 ...

最新文章

  1. Ubuntu16.04安装Chrome浏览器及解决root不能打开的问题
  2. 核心类生成-Mybatis Generator的使用
  3. 【大学课程】计算机网络知识点
  4. Heinz College of Information Systems and Public Policy Carnegie Mellon University
  5. int转string的3种方法
  6. 怎么让datagridview中的某一行不可编辑
  7. flutter 如何判断在哪个页面_Agora 教程:构建你的第一个 Flutter 视频通话应用
  8. linux内核多大 4.17.8,Linux Kernel 4.17结束支持,请升级到Linux 4.18内核
  9. Django操作原生MySQL的方法:MyModel.objects.raw()执行查询语句
  10. 非等高cell实战--实现微博页面
  11. linux服务端修改EDT为东八区,EDT开发环境配置
  12. QDUOJ LC的课后辅导 单调递增栈
  13. 全球名校AI课程库(23)| Harvard哈佛 · 基于Python/JavaScript的Web编程课程『Web Programming with Python and JavaScript』
  14. JCreator使用技巧
  15. 如何在屏幕实时显示键盘操作(独家分享)
  16. HTML table样式
  17. ERP系统功能之生产管理
  18. 一鸣心所向:可以直接套用的成交标准法则
  19. CeSi 进程集中管理部署
  20. java判断文件夹中的图片是否重复

热门文章

  1. 【原创】CSS3 制作奥林匹克五环
  2. opendrive网盘 一个能免费直接外链的网盘
  3. php中文输出有乱码怎么办,php中文输出乱码怎么办
  4. 论文中写伪代码的工具
  5. 民建浙江省委会副主委郭吉丰建言补齐数字经济短板
  6. js获取当前日期未来七天的日期
  7. 【历史上的今天】8 月 25 日:Linux 诞生;我国第一个计算机科学技术研究所成立
  8. Android获取软键盘输入内容
  9. 手机端,h5,获取位置,经度纬度
  10. 人与人的区别在于八小时之外如何运用