├── .gitignore
├── 番禺电费预警脚本
├── log
│ └── hello.log
├── requirements.txt
├── template
│ ├── notice.html
│ └── warning.html
├── config.py
├── emailTool.py
└── jnuWater.py
├── LICENSE
├── 青年大学习一键100%
├── getId.py
└── app.py
├── README.md
├── 番禺校区宿舍水费
└── app.py
├── 教务系统查询课表例子
├── app.py
└── des.js
└── 图书馆借阅快速答题
├── app.py
├── QA.json
└── des.js
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
--------------------------------------------------------------------------------
/番禺电费预警脚本/log/hello.log:
--------------------------------------------------------------------------------
1 | 此文件夹记录运行日志
--------------------------------------------------------------------------------
/番禺电费预警脚本/requirements.txt:
--------------------------------------------------------------------------------
1 | pandas== 1.2.4
2 | requests==2.27.1
3 | SQLAlchemy== 1.4.7
4 |
--------------------------------------------------------------------------------
/番禺电费预警脚本/template/notice.html:
--------------------------------------------------------------------------------
1 |
请自己修改通知邮件模版
2 | 例如:我们将暂停该服务
--------------------------------------------------------------------------------
/番禺电费预警脚本/template/warning.html:
--------------------------------------------------------------------------------
1 | 请自己修改提醒邮件模版
2 | 例如:该寝室的水电余额小于30元,请及时充值
--------------------------------------------------------------------------------
/番禺电费预警脚本/config.py:
--------------------------------------------------------------------------------
1 | # 准备一个数据库连接
2 | userName = 'root'
3 | password = 'root'
4 | host = '127.0.0.1'
5 | port = 3306
6 | database = 'jnu_water'
7 |
8 | # 准备邮箱相关配置
9 | # 注明:如果不是QQ邮箱可以到emailTool中把smtp.qq.com修改了
10 | sender = "xxxx@qq.com" # QQ邮箱
11 | authCode = "xxxx" # 授权码
12 |
13 | aimUrl = "http://127.0.0.1:xxxx/IBSJnuWeb/balance?" # 自己服务器中的路由
14 |
15 | # 使用:
16 | # 1. 填写该服务器数据库的相关信息
17 | # 2. 创建相关数据表格:打开jnuWater.py的注释Base.metadata.create_all(engine)并暂时人工注释该代码下的代码进行运行创建
18 | # 3. 填写邮箱/查询路由的URL(注意拼接是否与你当时的匹配请自己矫正)
19 | # 4. python jnuWater.py -k notice 进行运行
20 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2022 HengY1Coding✨
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/番禺电费预警脚本/emailTool.py:
--------------------------------------------------------------------------------
1 | # -*- coding:utf-8 -*-
2 | import smtplib
3 | from email.header import Header
4 | from email.mime.multipart import MIMEMultipart
5 | from email.mime.text import MIMEText
6 | from config import *
7 |
8 |
9 | def content(file_path):
10 | with open(file_path, encoding='utf-8') as f:
11 | return f.read()
12 |
13 |
14 | def send(subject, text, email):
15 | Subject = subject
16 | receivers = email # 收件人邮箱
17 | receivers = ','.join(receivers) if isinstance(receivers, list) else receivers
18 |
19 | message = MIMEMultipart('related')
20 | message['Subject'] = Subject
21 | message['From'] = '%s <%s>' % (Header('HengY1Service', 'utf-8'), sender)
22 | contentInfo = MIMEText(text, _subtype='html', _charset='UTF-8')
23 | message.attach(contentInfo)
24 | try:
25 | server = smtplib.SMTP_SSL("smtp.qq.com", 465)
26 | server.login(sender, authCode) # 授权码
27 | server.sendmail(sender, receivers.split(','), message.as_string())
28 | server.quit()
29 | except Exception as e:
30 | print('邮件发送异常, ', str(e))
31 |
32 |
33 | def readHtml(path):
34 | return content(path)
35 |
36 |
37 | if __name__ == "__main__":
38 | # 测试邮件发送
39 | send('宿舍电费预警通知(勿回)', '自定义HTML超文本部分', ['xxx@qq.com', 'xxx@qq.com'])
40 |
--------------------------------------------------------------------------------
/青年大学习一键100%/getId.py:
--------------------------------------------------------------------------------
1 | import json
2 | import datetime
3 | import requests
4 | import time
5 | from urllib.parse import urlencode
6 |
7 |
8 | # Warning ⚠️
9 | # 注意:反复登陆会导致需要验证码
10 | # 这时候用浏览器打开对应的网站登陆一次就好了
11 |
12 | class GetMid:
13 | def __init__(self, acc: str, password: str):
14 | self.acc = acc
15 | self.password = password
16 | self.session = None
17 | self.sunNum = 999
18 |
19 | def __login(self):
20 | nowTime = int(round(time.time() * 1000))
21 | data = {
22 | "userName": self.acc,
23 | "password": self.password,
24 | "loginValidCode": "",
25 | "_": nowTime
26 | }
27 | url = "https://tuanapi.12355.net/login/adminLogin?" + urlencode(data)
28 | s = requests.session()
29 | r = s.get(url)
30 | if r.json()['status'] != "OK":
31 | raise Exception(str(r.text))
32 | self.session = s
33 |
34 | def __getSunNum(self):
35 | # todo 获得oid
36 | nowTime = int(round(time.time() * 1000))
37 | url = "https://tuanapi.12355.net/login/getSessionAccount?_=" + str(nowTime)
38 | oid = self.session.get(url).json()['account']['oid']
39 | # todo 获得人数
40 | today = datetime.datetime.today()
41 | year = today.year
42 | month = '{:02d}'.format(today.month)
43 | yearMonth = str(year) + month
44 | data = {
45 | "curPage": 1,
46 | "pageSize": 1,
47 | "yearMonth": yearMonth,
48 | "oid": oid,
49 | "_": nowTime
50 | }
51 | header = {
52 | "authorize_name": str(oid)
53 | }
54 | url = "https://tuanapi.12355.net/api/bg/organizationStatistics/getOrgStatisticsLists?" + urlencode(data)
55 | r = self.session.get(url, headers=header)
56 | self.sunNum = r.json()['data']['OrgList'][0]['sumLeagueMember']
57 |
58 | def __getIdList(self):
59 | # todo 获取mid
60 | url = "https://tuanapi.12355.net/api/v1/admin/members/page"
61 | data = {
62 | "page": 1,
63 | "pageSize": int(self.sunNum)
64 | }
65 | header = {
66 | "Content-Type": "application/json",
67 | "Accept": "application/json, text/javascript, */*; q=0.01",
68 | "Origin": "https://tuan.12355.net",
69 | "Referer": "https://tuan.12355.net/",
70 | "Host": "tuanapi.12355.net",
71 | "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) "
72 | "Chrome/99.0.4844.83 Safari/537.36",
73 | }
74 | r = self.session.post(url, data=json.dumps(data), headers=header).json()
75 | listData = r['listData']
76 | midList = [each['mid'] for each in listData]
77 | return midList
78 |
79 | def run(self) -> list:
80 | try:
81 | self.__login()
82 | self.__getSunNum()
83 | return self.__getIdList()
84 | except Exception as e:
85 | print(f"获得错误:{str(e)}")
86 |
87 |
88 | if __name__ == "__main__":
89 | account, password = "", ""
90 | session = GetMid(account, password)
91 | idList = session.run()
92 | print(idList)
93 |
94 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 | # Jnu-ToolsBox
14 |
15 | _✨ 由@HengY1发起与维护 ✨_
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 | ## 项目定位 🌍
31 |
32 | > 👏欢迎大家成为本项目的参与者,踊跃提交PR与Issue
33 |
34 | 自己没事喜欢捣鼓,也为了方便大家快速找到所需资源,**避免重复造轮子**。
35 |
36 | 设计的所有PDF均已经上传到自搭网盘中,**方可有需自取下载**
37 |
38 | 现在**部分功能源码**已经开源,其余的正在路上...
39 |
40 | *我后端是由**Golang实现**的但是分层代码不好分享,所以采用**Python版本分享思路(~ ̄▽ ̄~)**
41 |
42 | ## 责任说明 🚀
43 |
44 | > *最终解释权归作者本人所有,请自觉遵守以下规则
45 |
46 | - 允许第三方 / 个人**无偿使用**
47 |
48 | - 若产生纠纷等问题,由使用者**自己承担**
49 |
50 | - 使用者需要**标注使用来源并且严格遵守开源协议**
51 |
52 | - 使用者未经允许**禁止收集用户个人隐私**
53 |
54 | - 使用者禁止使用该项目进行**封闭式的引流**
55 |
56 | - 使用者禁止**恶意使用接口,第三方有偿售卖/商用等行为**
57 |
58 | ## 课外拓展 🌟
59 |
60 | > 本分支主要面向面试,相关资料能够助力您冲击大厂
61 |
62 |
63 |
64 | > 👆以上截图于20220402,路漫漫其修远兮~
65 |
66 | | 名称 | 链接 | 取件码 |
67 | | :--------------: | :------------------------------------------------------: | :----: |
68 | | 数据结构算法分支 | https://github.com/HengY1Sky/Jnu-ToolsBox/tree/structure | 无 |
69 | | 八股文面试电子书 | https://yun.hengy1.top/s/JyFB | 885ucb |
70 |
71 | *以上的电子书本人几乎看完了,最后上传了质量不错的
72 |
73 | *在此在线求职**后端Go方向开发**,**收简历**的前辈请在ISSUE中留下邮箱(优先考虑大厂)
74 |
75 | > 目前本人在字节跳动后端实习中:提供修改简历,内推等服务。
76 |
77 | ## 第三方服务 🤔
78 |
79 | > 注意⚠️ 相关事项写在了文档详情中了,注意查收
80 | >
81 | > 部分接口学校服务器作为下游服务器,限定为每5秒请求一次(目前试运行具有保守性)
82 |
83 | 🦌 接口总路由: https://api.hengy1.top | 此域名 + 相对路由
84 |
85 | 🔎 文档详情:https://www.hengy1.top/service/ | 👈点击查看具体接口文档
86 |
87 | 🌍 APIFox在线文档:https://www.apifox.cn/apidoc/shared-8d20870a-7d59-4f28-ad08-aa1c4b97d726/api-20152758
88 |
89 | ----
90 |
91 | 😊 **宿舍水费预警/充值系统** => https://www.hengy1.top/service/JnuWater.html
92 |
93 | > 注册服务后将会**在每天的 8:00AM 以及 6:00PM 检测余额是否小于30元** (仅番禺校区)
94 |
95 | 😊 **教务系统** => https://www.hengy1.top/service/school.html
96 |
97 | > 教务系统暂时支持**本科生系统**(研究生系统没有账号)
98 | >
99 | > 教务系统连续错误5次即会锁账号,本服务错误4次即会在1小时内停止服务
100 |
101 | 😊 **健康每日打卡** => https://github.com/HengY1Sky/Jnu-Stuhealth
102 |
103 | 👇 以下的均在本仓库分支下的目录中(Python版本)
104 |
105 | 😊**青年大学习团委完成度** => 仅需要填写该团委的账号密码就好了
106 |
107 | 😊**图书馆借阅权限答题激活** => 内置题库,自动答题
108 |
109 | 😊**番禺校区水费查询源码** => 需要内网穿透才能提供公网服务
110 |
111 | 😊**番禺校区水费预警提醒脚本** => 面向第三方服务提供脚本(避免重复造轮子)
112 |
113 | 😊**教务系统通用方法** => 请保管好账号与密码,加强密码强度
114 |
115 | > 预警提醒脚本使用了第三方邮箱提醒服务,填写config.py中的配置参数即可。
116 |
117 | ## 绩点资料 📖
118 |
119 | - 对应分支 👉:https://github.com/HengY1Sky/Jnu-ToolsBox/tree/course
120 |
121 | | 学期 | 链接 | 取件码 |
122 | | :----------: | :---------------------------: | :----: |
123 | | 大一 | https://yun.hengy1.top/s/Xlh8 | 8gzf1m |
124 | | 大二上 | https://yun.hengy1.top/s/M2I8 | 07k973 |
125 | | 大二下 | https://yun.hengy1.top/s/EgHj | jjgc19 |
126 | | 大三上 | https://yun.hengy1.top/s/qWfD | kc91mw |
127 | | 大三下 | https://yun.hengy1.top/s/L0iq | gdwpql |
128 | | 数据结构期末 | https://yun.hengy1.top/s/YjHp | 7pefni |
129 |
130 | ## 新兵蛋子 🧪
131 |
132 | > 面向新生提供的建议~ 欢迎大家提交自己的博客链接 为新生提供有效的帮助 包括但不限于 学习 技术
133 | >
134 | > *请提交到ISSUE中:格式:描述---作者---链接
135 | >
136 | > 本人友链:https://www.hengy1.top/link/
137 |
138 | ----
139 |
140 | - [听说你组了比赛的队伍然后准备找个写程序的?](https://mp.weixin.qq.com/s/42zjXQc70o84HJlcVwV9xQ)
141 | - [别再说我们缺一个程序员了](https://www.hengy1.top/article/22239f7a.html)
142 |
143 | ## 贡献者 ✨
144 |
145 |
146 |
147 | ## 未来计划 ⌛️
148 |
149 | - 🏷️ ~~一键评教~~
150 |
151 | > 分析了下网络请求:成本大于使用效果,还是老老实实点点鼠标吧。写是能写,但是涉及的接口有点多。
152 |
--------------------------------------------------------------------------------
/番禺校区宿舍水费/app.py:
--------------------------------------------------------------------------------
1 | import json
2 | import re
3 | import time
4 | from Crypto.Cipher import AES
5 | import base64
6 | import requests
7 |
8 | ROOT_DOMAIN = "http://10.136.2.5/IBSjnuweb/"
9 |
10 |
11 | class IBSService:
12 | def __init__(self, acc: str):
13 | if acc == "":
14 | raise Exception("账号不能为空")
15 | self.key = "CetSoftEEMSysWeb"
16 | self.iv = b"\x19\x34\x57\x72\x90\xAB\xCD\xEF\x12\x64\x14\x78\x90\xAC\xAE\x45"
17 | self.__check(acc)
18 | self.__checkOnline()
19 |
20 | @staticmethod
21 | def getIBSClient() -> requests.Session:
22 | s = requests.Session()
23 | header = {
24 | "Content-Type": "application/json; charset=UTF-8",
25 | 'User-Agent': "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) "
26 | "Chrome/91.0.4472.77 Safari/537.36",
27 | "X-Forwarded-For": '127.0.0.1',
28 | }
29 | s.headers.update(header)
30 | return s
31 |
32 | @staticmethod
33 | def __checkOnline():
34 | try:
35 | requests.get(ROOT_DOMAIN, timeout=3)
36 | except requests.exceptions.ConnectTimeout:
37 | raise Exception("超时链接,请使用校园网/内网穿透")
38 |
39 | def __getEncrypt(self, text) -> str:
40 | text = text.replace(" ", "") # 这里是个大坑
41 | text = text.replace("|", " ") # 为了绕过中间的空格进入加密
42 | BS = 16
43 | pad = lambda s: s + (BS - len(s) % BS) * chr(BS - len(s) % BS)
44 | text = pad(text)
45 | o_aes = AES.new(self.key.encode(), AES.MODE_CBC, self.iv)
46 | esb = o_aes.encrypt(text.encode("UTF8"))
47 | return base64.b64encode(esb).decode("UTF8")
48 |
49 | def __check(self, acc):
50 | re_right = re.compile(r'^T(\d{5,6})$')
51 | if not re_right.match(acc):
52 | raise Exception("宿舍号不符合规则")
53 | self.acc = acc
54 |
55 | def __generateToken(self):
56 | timeArray = time.localtime(time.time())
57 | token_time = time.strftime("%Y-%m-%d | %H:%M:%S", timeArray)
58 | arr = {
59 | 'userID': self.customerId,
60 | 'tokenTime': token_time,
61 | }
62 | return self.__getEncrypt(json.dumps(arr))
63 |
64 | def __getIBSRequestHeader(self):
65 | timeArray = time.localtime(time.time())
66 | DateTime = time.strftime("%Y-%m-%d %H:%M:%S", timeArray)
67 | Header = {
68 | "Token": self.__generateToken(),
69 | 'DateTime': DateTime,
70 | }
71 | return Header
72 |
73 | def __login(self, paw):
74 | self.session = self.getIBSClient()
75 | postUrl = ROOT_DOMAIN + "WebService/JNUService.asmx/Login"
76 | postData = {"password": paw, "user": self.acc}
77 | responseRes = self.session.post(postUrl, json=postData)
78 | response = json.loads(responseRes.text)
79 | customerId = response['d']['ResultList'][0]['customerId']
80 | if customerId == 0:
81 | raise Exception("未能找到该宿舍")
82 | self.customerId = customerId
83 |
84 | def __getUserInfo(self):
85 | center_url = ROOT_DOMAIN + "WebService/JNUService.asmx/GetUserInfo"
86 | header = self.__getIBSRequestHeader()
87 | responseRes = self.session.post(center_url, headers=header)
88 | self.response = responseRes.text
89 |
90 | def __parseTxt(self):
91 | roomInfo = json.loads(self.response)['d']['ResultList'][0]['roomInfo']
92 | allowanceInfo = json.loads(self.response)['d']['ResultList'][0]['allowanceInfo']
93 | resultInfo = {
94 | 'balance': roomInfo[1]['keyValue'],
95 | 'subsidies': allowanceInfo[0]['keyValue'],
96 | }
97 | return resultInfo
98 |
99 | def run(self):
100 | try:
101 | paw = self.__getEncrypt(self.acc)
102 | self.__login(paw) # 进行登陆
103 | self.__getUserInfo() # 拿到信息
104 | res = self.__parseTxt() # 分析结果
105 | print(res)
106 | except Exception as e:
107 | print("发生错误", e)
108 |
109 |
110 | if __name__ == '__main__':
111 | print("[*] 更多信息在:https://github.com/HengY1Sky/Jnu-ToolsBox 作者:HengY1")
112 | print("[*] ROOT_DOMAIN为学校官网,但是只能校内访问")
113 | print("[*] 若要提供公网访问则需要进行内网穿透~")
114 | print("[*] 更多接口只需要更换对应的路径即可然后解析内容 ✧(≖ ◡ ≖✿)")
115 | IBSService("T110222").run()
116 |
--------------------------------------------------------------------------------
/番禺电费预警脚本/jnuWater.py:
--------------------------------------------------------------------------------
1 | import os.path
2 | import time
3 | from datetime import datetime, date
4 | import logging
5 | import argparse
6 | from concurrent.futures import ThreadPoolExecutor, as_completed
7 | import requests
8 | from sqlalchemy import create_engine, Column, Integer, String, DateTime, and_, delete
9 | from sqlalchemy.orm import declarative_base, Session
10 | from emailTool import send, readHtml
11 | from config import *
12 |
13 | # 声明一个数据库引擎
14 | engine = create_engine(
15 | f'mysql+mysqlconnector://{userName}:{password}@{host}:{port}/{database}?auth_plugin=mysql_native_password',
16 | future=True)
17 |
18 | # 声明ORM的一个基类并建立映射关系
19 | Base = declarative_base()
20 |
21 |
22 | class emailNotice(Base):
23 | """邮件通知表格"""
24 | __tablename__ = 'email_notice'
25 | id = Column(Integer, name='id', primary_key=True)
26 | email = Column(String(64), nullable=False, name='email', comment="注册邮箱")
27 | dormitory = Column(String(64), nullable=False, name='dormitory', comment="绑定宿舍")
28 | ip = Column(String(64), nullable=False, name='ip', comment="注册Ip")
29 | create_at = Column(DateTime, name='create_at', comment="创建时间")
30 | update_at = Column(DateTime, name='update_at', comment="更新时间")
31 | is_verify = Column(Integer, name='is_verify', default=0, comment="是否通过邮箱验证")
32 | is_work = Column(Integer, name='is_work', default=1, comment='是否仍然生效')
33 |
34 |
35 | # Base.metadata.create_all(engine) # 解除该注释即可以创建对应的数据表格
36 |
37 | # todo 查询有效用户
38 | def findWhoCouldUseIt(): # is_verify且任然在is_work
39 | session = Session(bind=engine, future=True)
40 | info = session.query(emailNotice).filter(and_(emailNotice.is_verify == 1, emailNotice.is_work == 1)).all()
41 | return info
42 |
43 |
44 | # todo 查询余额
45 | def getBalance(infoList) -> list:
46 | needList = []
47 | executor = ThreadPoolExecutor(max_workers=5)
48 | allTask = [executor.submit(netWay, each) for each in infoList]
49 | for future in as_completed(allTask): # 获取到已经完成的了
50 | flag, email = future.result()
51 | if flag:
52 | needList.append(email)
53 | return needList
54 |
55 |
56 | def netWay(eachInfo):
57 | try:
58 | email, dormitoryNum = eachInfo
59 | res = requests.get(aimUrl + f"dormitory={dormitoryNum}", timeout=30, verify=False).json()
60 | balance = res['data']['balance']
61 | if int(balance) < 30:
62 | return True, email
63 | return False, -1
64 | except Exception as e:
65 | logger.info('Error Occurred : %s', e)
66 | return False, -1
67 |
68 |
69 | # todo 处理群发
70 | def queueSend(needNoticeList):
71 | resList = []
72 | for x in range(0, len(needNoticeList), 20):
73 | resList.append(needNoticeList[x: x + 20])
74 | return resList
75 |
76 |
77 | # todo 查询接口并通知对应的用户
78 | def noticeUser():
79 | try:
80 | # todo 找到需要通知的
81 | resMaps = findWhoCouldUseIt()
82 | if list(resMaps) == 0:
83 | logging.info("查询到0个用户")
84 | return
85 | baseInfoList = [(each.email, each.dormitory) for each in resMaps]
86 | needNoticeList = getBalance(baseInfoList)
87 | # todo 发送通知
88 | subject = '宿舍电费预警通知(勿回)'
89 | needNoticeList = queueSend(needNoticeList)
90 | body = readHtml(os.path.join(templatePath, "warning.html"))
91 | for each in needNoticeList:
92 | logging.info(f"查询:{str(each)}")
93 | time.sleep(10) # 休息10秒钟 即使群发但是只要高频率调用QQ第三方服务会拒绝
94 | send(subject, body, each)
95 | # todo 通知管理者
96 | send(f"[*] 查询成功", f"时间:{timeNow}, 通知了:{str(needNoticeList)}", sender)
97 | except Exception as e:
98 | send(f"[*] 查询失败", f"时间:{timeNow}, {e}", sender)
99 | logger.error('Error Occurred : %s', e)
100 |
101 |
102 | # todo 删除每日失效用户(平时不使用)
103 | def deleteUser():
104 | try:
105 | session = Session(bind=engine, future=True)
106 | stmt = delete(emailNotice).where(emailNotice.is_verify == 0)
107 | resInfo = session.execute(stmt)
108 | session.commit()
109 | logging.info(f"删除了:{resInfo.rowcount}条")
110 | except Exception as e:
111 | send(f"[*] 删除每日失效用户失败", f"时间:{timeNow}, {e}", sender)
112 | logger.error('Error Occurred : %s', e)
113 |
114 |
115 | # todo 通知所有人消息(平时不使用)
116 | def radioNotice():
117 | try:
118 | session = Session(bind=engine, future=True)
119 | info = session.query(emailNotice).filter(and_(emailNotice.is_verify == 1, emailNotice.is_work == 1)).all()
120 | allUser = [x.email for x in info]
121 | allUser = queueSend(allUser)
122 | subject = '新一年预警服务开启'
123 | body = readHtml(os.path.join(templatePath, "notice.html"))
124 | for x in allUser:
125 | logging.info(f"查询:{str(x)}")
126 | send(subject, body, x)
127 | except Exception as e:
128 | logger.error('Error Occurred : %s', e)
129 |
130 |
131 | if __name__ == "__main__":
132 | # todo 设置路径
133 | currentPath = str.rsplit(__file__, '/', 1)[0].replace("jnuWater.py", "")
134 | logPath = os.path.join(currentPath, "log")
135 | fileName = os.path.join(logPath, date.today().strftime("%Y_%m") + ".log")
136 | timeNow = datetime.now().strftime("%d/%m/%Y %H:%M:%S")
137 | templatePath = os.path.join(currentPath, "template")
138 | # todo 设置日志
139 | logging.basicConfig(level=logging.INFO,
140 | filename=fileName,
141 | datefmt='%Y/%m/%d %H:%M:%S',
142 | format='%(asctime)s - %(name)s - %(levelname)s - %(lineno)d - %(module)s - %(message)s')
143 | logger = logging.getLogger(__name__)
144 | # todo 任务
145 | parser = argparse.ArgumentParser(
146 | description='Water warning system by Python.',
147 | formatter_class=argparse.RawTextHelpFormatter
148 | )
149 | parser.add_argument(
150 | '-k',
151 | '--key',
152 | required=False,
153 | type=str,
154 | help='Keywords to be present in the title'
155 | )
156 | args = parser.parse_args()
157 | if args.key == 'delete':
158 | deleteUser() # 删除每日失效用户
159 | elif args.key == 'notice':
160 | noticeUser() # 查询接口并通知对应的用户
161 | else:
162 | logging.info("参数解析错误")
163 | # radioNotice() # 通知所有人消息
164 |
--------------------------------------------------------------------------------
/青年大学习一键100%/app.py:
--------------------------------------------------------------------------------
1 | import threading
2 | from getId import GetMid
3 | import requests
4 | import urllib.parse
5 | from tqdm import tqdm
6 | from concurrent.futures import ThreadPoolExecutor
7 | from collections import Counter
8 |
9 | # 有啥问题直接开ISSUE即可
10 | # 项目地址:https://github.com/HengY1Sky/Jnu-ToolsBox
11 |
12 | def makeHeader(host, origin, referer):
13 | headers = {
14 | 'Host': host,
15 | 'Origin': origin,
16 | 'Referer': referer,
17 | 'X-Litemall-Token': '',
18 | 'X-Litemall-IdentiFication': 'young',
19 | 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) '
20 | 'Chrome/51.0.2704.103 Safari/537.36',
21 | 'Accept': '*/*',
22 | 'Content-Type': 'application/x-www-form-urlencoded',
23 | 'X-Requested-With': 'com.tencent.mm',
24 | 'Sec-Fetch-Site': 'same-origin',
25 | 'Sec-Fetch-Mode': 'cors',
26 | 'Accept-Encoding': 'gzip, deflate',
27 | 'Accept-Language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7'
28 | }
29 | return headers
30 |
31 |
32 | class AppMain:
33 | def __init__(self, acc: str, pas: str):
34 | self.lock = threading.RLock()
35 | self.acc = acc
36 | self.pas = pas
37 | self.idList = None
38 | self.failList = []
39 | self.success = 0
40 | self.errList = []
41 | self.lock = threading.Lock()
42 |
43 | @staticmethod
44 | def getSign(mid):
45 | url = "https://tuanapi.12355.net/questionnaire/getYouthLearningUrl?mid=" + str(mid)
46 | response = requests.get(url, headers=makeHeader('tuanapi.12355.net',
47 | 'https://tuan.12355.net',
48 | 'https://tuan.12355.net/wechat/view/YouthLearning/page.html'))
49 | resJson = response.json()
50 | signUrl = resJson['youthLearningUrl']
51 | sign = signUrl.split('?')
52 | return sign[1][5:]
53 |
54 | @staticmethod
55 | def getToken(sign):
56 | payload = "sign=" + urllib.parse.quote(sign)
57 | url = "https://youthstudy.12355.net/apih5/api/user/get"
58 | response = requests.post(url, headers=makeHeader('youthstudy.12355.net',
59 | 'https://youthstudy.12355.net',
60 | 'https://youthstudy.12355.net/h5/'), data=payload)
61 | resJson = response.json()
62 | return resJson["data"]["entity"]["token"]
63 |
64 | @staticmethod
65 | def getChapterId():
66 | url = "https://youthstudy.12355.net/apih5/api/young/chapter/new"
67 | headers = {
68 | 'X-Litemall-IdentiFication': 'young'
69 | }
70 | response = requests.get(url, headers=headers)
71 | j = response.json()
72 | return j["data"]["entity"]["id"]
73 |
74 | @staticmethod
75 | def finalDone(token, cid):
76 | headers = makeHeader('youthstudy.12355.net', 'https://youthstudy.12355.net', 'https://youthstudy.12355.net/h5/')
77 | headers["X-Litemall-Token"] = token
78 | url = "https://youthstudy.12355.net/apih5/api/young/course/chapter/saveHistory"
79 | payload = "chapterId=" + str(cid)
80 | response = requests.post(url, headers=headers, data=payload)
81 | j = response.json()
82 | return j
83 |
84 | def factory(self, mid: int) -> (bool, int):
85 | try:
86 | cid = self.getChapterId()
87 | sign = self.getSign(mid)
88 | token = self.getToken(sign)
89 | res = self.finalDone(token, cid)
90 | if res["errno"] == 0:
91 | return True, 0
92 | else:
93 | self.lock.acquire()
94 | self.errList.append(res['errmsg'])
95 | self.lock.release()
96 | return False, mid
97 | except Exception as e:
98 | self.lock.acquire()
99 | self.errList.append(str(e))
100 | self.lock.release()
101 | print(f"[*] mid为:{mid}发生错误:{e}")
102 | return False, mid
103 |
104 | def __initList(self):
105 | try:
106 | self.idList = GetMid(self.acc, self.pas).run()
107 | except Exception as e:
108 | print(f"initList 发生错误:{e}")
109 | exit()
110 |
111 | def __doMission(self):
112 | # todo 判断数量
113 | if len(self.idList) == 0:
114 | print(f"[*] initList 数量为0")
115 | exit()
116 | # todo 多线程执行
117 | with tqdm(total=len(self.idList)) as pbar:
118 | pbar.set_description('Processing:')
119 | executor = ThreadPoolExecutor(max_workers=2)
120 | for data in executor.map(self.factory, self.idList):
121 | pbar.update(1)
122 | flag, mid = data
123 | if not flag:
124 | self.failList.append(mid)
125 | else:
126 | self.success += 1
127 | # todo 显示错误原因以及次数
128 | result = Counter(self.errList)
129 | print("[*] " + str(result))
130 | # todo 再次执行错误名单
131 | if self.failList:
132 | print("[*] 存在错误名单,开始修复")
133 | temp = []
134 | with tqdm(total=len(self.failList)) as pbar:
135 | pbar.set_description('Fixing:')
136 | for each in self.failList:
137 | flag, _ = self.factory(each)
138 | pbar.update(1)
139 | if not flag:
140 | temp.append(each)
141 | else:
142 | self.success += 1
143 | self.failList = temp
144 | # todo 处理结果
145 | rate = round(self.success / len(self.idList), 2) * 100
146 | print(f"[*] 总人数:{len(self.idList)} 成功为:{self.success} 学习完成率为:{rate}")
147 | print(f"[*] 失败人数:{len(self.failList)} 为{str(self.failList)}")
148 | print("[*] 任务完成")
149 |
150 | def run(self):
151 | self.__initList()
152 | self.__doMission()
153 |
154 |
155 | if __name__ == "__main__":
156 | print("更多信息请到:https://github.com/HengY1Sky/Jnu-ToolsBox")
157 | account, password = "", ""
158 | newOne = AppMain(account, password)
159 | newOne.run()
--------------------------------------------------------------------------------
/教务系统查询课表例子/app.py:
--------------------------------------------------------------------------------
1 | import urllib.parse
2 | from requests import cookies
3 | import execjs
4 | from bs4 import BeautifulSoup
5 | import time
6 | import urllib.parse
7 | import requests
8 |
9 |
10 | def getHeader():
11 | header = {
12 | "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:98.0) Gecko/20100101 Firefox/98.0",
13 | "Host": "icas.jnu.edu.cn",
14 | "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8",
15 | "Origin": "https://icas.jnu.edu.cn",
16 | "Referer": "https://icas.jnu.edu.cn/cas/login?service=https://info.jnu.edu.cn/",
17 | "Content-Type": "application/x-www-form-urlencoded",
18 | }
19 | return header
20 |
21 |
22 | def getScheduleHeader():
23 | headers = {
24 | "authority": "jw.jnu.edu.cn",
25 | "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,"
26 | "image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
27 | "accept-language": "zh-CN,zh;q=0.9",
28 | "referer": "https://jw.jnu.edu.cn/new/index.html",
29 | "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) "
30 | "Chrome/100.0.4896.60 Safari/537.36"
31 | }
32 | return headers
33 |
34 |
35 | class LoginScript:
36 | def __init__(self, acc: str, paw: str):
37 | self.jwUrl = "https://icas.jnu.edu.cn/cas/login?service=" \
38 | "https%3A%2F%2Fauth5.jnu.edu.cn%2Frump_frontend%2FloginFromCas%2F"
39 | self.paw, self.acc = None, None
40 | self.__check(acc, paw)
41 | self.lt = None
42 | self.execution = None
43 | try:
44 | self.__parse()
45 | self.rsa = None
46 | self.___getDes()
47 | except Exception as e:
48 | print(f"[*] 初始化工作错误:{e}")
49 |
50 | def ___getDes(self):
51 | with open('des.js', 'r', encoding='UTF-8') as f:
52 | js_code = f.read()
53 | data = self.acc + self.paw + self.lt
54 | firstKey, secondKey, thirdKey = "1", "2", "3"
55 | self.rsa = execjs.compile(js_code).call("strEnc", data, firstKey, secondKey, thirdKey)
56 |
57 | def __check(self, acc, paw):
58 | if acc == "" or paw == "":
59 | raise Exception("账号/密码不能为空")
60 | self.acc = acc
61 | self.paw = paw
62 |
63 | def __parse(self):
64 | url = "https://icas.jnu.edu.cn/cas/login"
65 | r = requests.get(url)
66 | soup = BeautifulSoup(r.text, 'lxml')
67 | self.lt = soup.select('#lt')[0].attrs['value']
68 | self.execution = soup.select('#loginForm > input[type=hidden]:nth-child(9)')[0].attrs['value']
69 |
70 | def __getSession(self):
71 | # todo 拿到session 此处的session只能使用一次
72 | header = getHeader()
73 | temp = requests.session()
74 | temp.get(url=self.jwUrl, headers=header, allow_redirects=False)
75 | cookie = temp.cookies.get_dict()
76 | lastSession = cookie['JSESSIONID']
77 | # todo 拿到对应的跳转链接
78 | sessions = requests.session()
79 | data = {
80 | "rsa": self.rsa,
81 | "ul": len(self.acc),
82 | "pl": len(self.paw),
83 | "lt": self.lt,
84 | "execution": self.execution,
85 | "_eventId": "submit"
86 | }
87 | cookie = {
88 | "JSESSIONID": lastSession,
89 | }
90 | r = sessions.post(url=self.jwUrl, headers=header, data=data, allow_redirects=False, cookies=cookie)
91 | header = r.headers
92 | # todo 拿到通行证
93 | if 'Location' in header.keys():
94 | location = header['Location']
95 | query = dict(urllib.parse.parse_qsl(urllib.parse.urlsplit(location).query))
96 | jar = requests.cookies.RequestsCookieJar()
97 | jar.set("own-ticket", query['ticket'])
98 | sessions.cookies.update(jar)
99 | sessions.get(url=location, headers=header, allow_redirects=False)
100 | return sessions
101 | else:
102 | raise Exception("账号密码错误 \n 多次错误将会导致账号被锁")
103 |
104 | def login(self) -> requests.Session:
105 | return self.__getSession()
106 |
107 |
108 | class GetSchedule:
109 | def __init__(self, session: requests.Session):
110 | self.json = None
111 | self.session = session
112 | self.scheduleId = 4770397878132218 # 为课表的ID
113 |
114 | def ImitateJump(self, way: int, fromWhere: str):
115 | try:
116 | if way == 1:
117 | r = self.session.post(url=fromWhere, headers=getScheduleHeader(), allow_redirects=False)
118 | else:
119 | r = self.session.get(url=fromWhere, headers=getScheduleHeader(), allow_redirects=False)
120 | header = r.headers
121 | if 'Location' in header.keys():
122 | return header['Location']
123 | else:
124 | return ""
125 | except Exception as e:
126 | print(f"[*] form {fromWhere} Error: {e}")
127 | return ""
128 |
129 | def __getSessionToken(self):
130 | # todo 为了Token
131 | url = "https://jw.jnu.edu.cn//amp-auth-adapter/login?" \
132 | "service=http%3A%2F%2Fjw.jnu.edu.cn%2Flogin%3Fservice%3Dhttps%3A%2F%2Fjw.jnu.edu.cn%2Fnew%2Findex.html"
133 | url = self.ImitateJump(0, url) # 拿到跳转的sessionToken
134 | query = dict(urllib.parse.parse_qsl(urllib.parse.urlsplit(url).query))
135 | aim = query['service'] # 因为是跳转 拿到后面的
136 | query = dict(urllib.parse.parse_qsl(urllib.parse.urlsplit(aim).query)) # 再次分析
137 | jar = requests.cookies.RequestsCookieJar()
138 | jar.set("own-token", query['sessionToken'])
139 | self.session.cookies.update(jar)
140 |
141 | def __getJsID(self):
142 | # todo 为了拿到_WEN有效
143 | nowTime = int(round(time.time() * 1000))
144 | url = "https://jw.jnu.edu.cn/jsonp/serviceCenterData.json?containLabels=true&searchKey=&_=" + str(nowTime)
145 | self.session.get(url, headers=getScheduleHeader())
146 |
147 | def __getRealTicket(self):
148 | # todo 为了拿到通行证
149 | cookie = self.session.cookies.get_dict()
150 | url = "https://icas.jnu.edu.cn/cas/login?" \
151 | "service=http%3A%2F%2Fjw.jnu.edu.cn%2Famp-auth-adapter%2FloginSuccess%3FsessionToken%3D" + cookie[
152 | 'own-token']
153 | # 以下不写循环 仅仅是为了注释每一步
154 | url = self.ImitateJump(0, url)
155 | url = self.ImitateJump(0, url) # 这里是一块跳板
156 | url = self.ImitateJump(0, url) # 这里成功拿到真正的ticket并且存入新的CASTGC
157 | url = self.ImitateJump(0, url, ) # 这里为301永久定向也是跳板
158 | self.ImitateJump(0, url) # 成功把MOD_AMP_AUTH存入
159 |
160 | def __getWENCookie(self):
161 | # todo 拿到最后一个cookie
162 | # todo 先拿到gid跳转链接
163 | url = "https://jw.jnu.edu.cn/appShow?appId=" + str(self.scheduleId)
164 | url = self.ImitateJump(0, url)
165 | self.session.get(url, headers=getScheduleHeader())
166 |
167 | def __getSchedule(self):
168 | cookieDict = self.session.cookies.get_dict()
169 | # todo 拿到课表
170 | headers = {
171 | "authority": "jw.jnu.edu.cn",
172 | "accept": "application/json, text/javascript, */*; q=0.01",
173 | "accept-language": "zh-CN,zh;q=0.9",
174 | "content-type": "application/x-www-form-urlencoded; charset=UTF-8",
175 | "origin": "https://jw.jnu.edu.cn",
176 | "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) "
177 | "Chrome/100.0.4896.60 Safari/537.36",
178 | "x-requested-with": "XMLHttpRequest"
179 | }
180 | cookie = {
181 | "_WEU": cookieDict['_WEU'],
182 | "client_vpn_ticket": cookieDict['client_vpn_ticket'],
183 | "MOD_AMP_AUTH": cookieDict['MOD_AMP_AUTH'],
184 | }
185 | url = "https://jw.jnu.edu.cn/jwapp/sys/wdkb/modules/xskcb/xskcb.do"
186 | data = {
187 | "XNXQDM": "2021-2022-2"
188 | }
189 | response = requests.post(url, headers=headers, data=data, cookies=cookie)
190 | self.json = response.json()
191 |
192 | def __parseJson(self):
193 | info = self.json['datas']['xskcb']
194 | total = info['totalSize']
195 | print(f'[*] 查询到数量:{total}')
196 | rows = info['rows']
197 | dicFunc = lambda x: (x['KKDWDM_DISPLAY'], x['SKJS'], x['XXXQDM_DISPLAY'], x['YPSJDD'])
198 | res = [dicFunc(each) for each in rows]
199 | for each in res:
200 | college, teacher, where, detail = each
201 | print(f'[*] 来自{college} 老师:{teacher}, 校区:{where}, 细节:{detail}')
202 |
203 | def run(self):
204 | try:
205 | self.__getSessionToken()
206 | self.__getJsID()
207 | self.__getRealTicket()
208 | self.__getWENCookie()
209 | self.__getSchedule()
210 | self.__parseJson()
211 | except Exception as e:
212 | print(f"[*] 错误:{e}")
213 |
214 |
215 | if __name__ == "__main__":
216 | print("[*] 更多信息:https://github.com/HengY1Sky/Jnu-ToolsBox")
217 | print("[*] 连续多次错误将会导致校园网被锁")
218 | print("[*] scheduleId换成别的后都是一个道理拿到对应的cookie就可以请求接口了")
219 | print("[*] 因为有多次跳转可能部分时候会失效 \n[*] 重试即可")
220 | account, password = "", ""
221 | s = LoginScript(account, password).login()
222 | schedule = GetSchedule(s)
223 | schedule.run()
224 |
--------------------------------------------------------------------------------
/图书馆借阅快速答题/app.py:
--------------------------------------------------------------------------------
1 | import json
2 | import os
3 | import random
4 | import time
5 | import urllib.parse
6 | from requests import cookies
7 | import execjs
8 | from bs4 import BeautifulSoup
9 | import urllib.parse
10 | import requests
11 |
12 | STEP = {
13 | 0: "7f6d456b-2372-4b80-8e5a-0f6bf8c979c4",
14 | 1: "c26f7e15-3fd6-4fcc-a2ee-2d72ec4dc725",
15 | 2: "3d45bec2-f8b8-48a6-a168-868db11b43c0",
16 | 3: "a529aa60-4246-4a33-9879-04f5ec6951e2",
17 | 4: "20105737-bde6-4e0a-8c2f-f4f07e0016e8",
18 | 5: "8f5e0400-e582-41be-afaa-3810faf3ef99",
19 | }
20 |
21 |
22 | def getHeader():
23 | header = {
24 | "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:98.0) Gecko/20100101 Firefox/98.0",
25 | "Host": "icas.jnu.edu.cn",
26 | "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8",
27 | "Origin": "https://icas.jnu.edu.cn",
28 | "Referer": "https://icas.jnu.edu.cn/cas/login?service=https://info.jnu.edu.cn/",
29 | "Content-Type": "application/x-www-form-urlencoded",
30 | }
31 | return header
32 |
33 |
34 | def getLibHeader():
35 | header = {
36 | "Host": "libtrain.jnu.edu.cn",
37 | "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:99.0) Gecko/20100101 Firefox/99.0",
38 | "Referer": "https://libtrain.jnu.edu.cn/Web/User"
39 | }
40 | return header
41 |
42 |
43 | class LoginScript:
44 | def __init__(self, acc: str, paw: str):
45 | self.jwUrl = "https://icas.jnu.edu.cn/cas/login?service=https://libtrain.jnu.edu.cn/api/index/login"
46 | self.paw, self.acc = None, None
47 | self.__check(acc, paw)
48 | self.lt = None
49 | self.execution = None
50 | try:
51 | self.__parse()
52 | self.rsa = None
53 | self.___getDes()
54 | except Exception as e:
55 | print(f"[*] 初始化工作错误:{e}")
56 |
57 | def ___getDes(self):
58 | with open('des.js', 'r', encoding='UTF-8') as f:
59 | js_code = f.read()
60 | data = self.acc + self.paw + self.lt
61 | firstKey, secondKey, thirdKey = "1", "2", "3"
62 | self.rsa = execjs.compile(js_code).call("strEnc", data, firstKey, secondKey, thirdKey)
63 |
64 | def __check(self, acc, paw):
65 | if acc == "" or paw == "":
66 | raise Exception("账号/密码不能为空")
67 | self.acc = acc
68 | self.paw = paw
69 |
70 | def __parse(self):
71 | url = "https://icas.jnu.edu.cn/cas/login"
72 | r = requests.get(url)
73 | soup = BeautifulSoup(r.text, 'lxml')
74 | self.lt = soup.select('#lt')[0].attrs['value']
75 | self.execution = soup.select('#loginForm > input[type=hidden]:nth-child(9)')[0].attrs['value']
76 |
77 | def __getSession(self):
78 | # todo 拿到session 此处的session只能使用一次
79 | header = getHeader()
80 | temp = requests.session()
81 | temp.get(url=self.jwUrl, headers=header, allow_redirects=False)
82 | cookie = temp.cookies.get_dict()
83 | lastSession = cookie['JSESSIONID']
84 | # todo 拿到对应的跳转链接
85 | sessions = requests.session()
86 | data = {
87 | "rsa": self.rsa,
88 | "ul": len(self.acc),
89 | "pl": len(self.paw),
90 | "lt": self.lt,
91 | "execution": self.execution,
92 | "_eventId": "submit"
93 | }
94 | cookie = {
95 | "JSESSIONID": lastSession,
96 | }
97 | r = sessions.post(url=self.jwUrl, headers=header, data=data, allow_redirects=False, cookies=cookie)
98 | header = r.headers
99 | # todo 拿到通行证
100 | if 'Location' in header.keys():
101 | location = header['Location']
102 | query = dict(urllib.parse.parse_qsl(urllib.parse.urlsplit(location).query))
103 | jar = requests.cookies.RequestsCookieJar()
104 | jar.set("own-ticket", query['ticket'])
105 | sessions.cookies.update(jar)
106 | sessions.get(url=location, headers=header, allow_redirects=False)
107 | return sessions
108 | else:
109 | raise Exception("账号密码错误 \n 多次错误将会导致账号被锁")
110 |
111 | def login(self) -> requests.Session:
112 | return self.__getSession()
113 |
114 |
115 | class GetRootPass:
116 | def __init__(self, acc: str, paw: str):
117 | self.__ping() # 检查网络
118 | self.json = None
119 | self.__loadJson() # 加载答案库
120 | self.acc = None
121 | self.paw = None
122 | self.session = None
123 | self.__checkAndLogin(acc, paw) # 检查账号是否正确
124 | self.step = 0
125 | self.stepUrl = None
126 | self.examId = None
127 | self.questionList = None
128 |
129 | @staticmethod
130 | def __ping():
131 | try:
132 | requests.get("https://libtrain.jnu.edu.cn/")
133 | print("[*] 校园网通畅~")
134 | except Exception as e:
135 | raise Exception("请在校园网内操作~")
136 |
137 | def __loadJson(self):
138 | try:
139 | filePath = os.path.dirname(__file__)
140 | jsonPath = os.path.join(filePath, 'QA.json')
141 | with open(jsonPath, 'r') as load_f:
142 | self.json = json.load(load_f)
143 | print("[*] 答案库加载完毕")
144 | except Exception as e:
145 | raise e
146 |
147 | def __checkAndLogin(self, acc: str, paw: str):
148 | if acc == "" or paw == "":
149 | raise Exception("账号密码不能为空")
150 | try:
151 | self.session = LoginScript(acc, paw).login()
152 | self.acc, self.paw = acc, paw
153 | print("[*] 账号密码验证成功")
154 | except Exception as e:
155 | raise e
156 |
157 | def __getUid(self):
158 | aimUrl = "https://libtrain.jnu.edu.cn/web/User/cblogin?userid=" + self.acc + "&shcool=jndx"
159 | self.session.get(aimUrl, headers=getLibHeader(), allow_redirects=False)
160 |
161 | def __getJumpUrl(self):
162 | # todo 拿到跳转链接
163 | try:
164 | aimUrl = "https://libtrain.jnu.edu.cn/Web/User"
165 | jar = requests.cookies.RequestsCookieJar()
166 | jar.set("from", "0")
167 | self.session.cookies.update(jar)
168 | r = self.session.get(aimUrl, headers=getLibHeader())
169 | soup = BeautifulSoup(r.text, 'lxml')
170 | self.stepUrl = soup.select(".operatelist")[0].contents[1].attrs['href']
171 | self.__getUid()
172 | except Exception as e:
173 | raise Exception(f"getJumpUrl错误 {e}")
174 |
175 | def __judgeStep(self):
176 | try:
177 | aimUrl = "https://libtrain.jnu.edu.cn/Web/Exam?cid=" + STEP[self.step]
178 | r = self.session.get(aimUrl, headers=getLibHeader(), allow_redirects=False)
179 | while 'Location' in r.headers:
180 | self.step += 1
181 | if self.step == 6:
182 | break
183 | aimUrl = "https://libtrain.jnu.edu.cn/Web/Exam?cid=" + STEP[self.step]
184 | time.sleep(0.5)
185 | r = self.session.get(aimUrl, headers=getLibHeader(), allow_redirects=False)
186 | current = {
187 | 0: "初中生", 1: "高中生", 2: "大学生", 3: "研究生", 4: "博士生", 5: "博士后", 6: "答题完毕",
188 | }
189 | print(f'[*] 当前的步骤为{current[self.step]}')
190 | if self.step == 6:
191 | print("[*] 答题退出")
192 | exit(0)
193 | jar = requests.cookies.RequestsCookieJar()
194 | jar.set("real-cid", STEP[self.step])
195 | self.session.cookies.update(jar)
196 | except Exception as e:
197 | raise Exception(f"judgeStep 发生错误:{e}")
198 |
199 | def __getStart(self):
200 | try:
201 | # todo 只要请求一次就是开启了新的了
202 | aimUrl = "https://libtrain.jnu.edu.cn/Web/Exam?cid=" + self.session.cookies.get_dict()['real-cid']
203 | r = self.session.get(aimUrl, headers=getLibHeader())
204 | soup = BeautifulSoup(r.text, 'lxml')
205 | self.examId = soup.select("#examRecordDetailsId")[0].attrs['value'] # 本次答题的编号
206 | self.questionList = soup.select("#stIds")[0].attrs['value'].split(",") # 本次题号
207 | except Exception as e:
208 | raise Exception(f"getStart 发生错误:{e}")
209 |
210 | def __ifCorrect(self):
211 | try:
212 | aimUrl = "https://libtrain.jnu.edu.cn/web/exam/GetGameRole"
213 | spend = str(random.randint(8, 32))
214 | data = {
215 | "zid": self.session.cookies.get_dict()['real-cid'],
216 | "examRecordDetailsId": self.examId,
217 | "spendtime": spend,
218 | }
219 | r = self.session.post(aimUrl, data=data, headers=getLibHeader()).json()
220 | print(f"[*] 当前阶段 {r['Msg']}")
221 | except Exception as e:
222 | raise Exception(f"ifCorrect 发生错误:{e}")
223 |
224 | def __getAns(self):
225 | try:
226 | aimUrl = "https://libtrain.jnu.edu.cn/web/Exam/GetAnswer"
227 | total = 0
228 | for each in self.questionList: # 一道道题来做
229 | flag = False
230 | ans, spend = None, str(random.randint(8, 32)) # 处理每一道题的答案/耗时
231 | for eachAns in self.json:
232 | if eachAns['question'] == each: # 如果找得到
233 | ans = str(eachAns['answer']).replace(",", "%2C")
234 | data = {
235 | "stid": each,
236 | "answer": ans,
237 | "zid": self.session.cookies.get_dict()['real-cid'],
238 | "examRecordDetailsId": self.examId,
239 | "spendtime": spend,
240 | "helpId": "00000000-0000-0000-0000-000000000000"
241 | }
242 | self.session.post(aimUrl, data=data).json()
243 | total += 1
244 | flag = True
245 | break
246 | if flag: # 如果为真则这道题搞定了
247 | continue
248 | else: # 添加进入题库
249 | data = {
250 | "stid": each,
251 | "answer": "6c9148c6-6841-4c01-8bc6-1e350b0c0daf", # 随便搪塞一个
252 | "zid": self.session.cookies.get_dict()['real-cid'],
253 | "examRecordDetailsId": self.examId,
254 | "spendtime": spend,
255 | "helpId": "00000000-0000-0000-0000-000000000000"
256 | }
257 | r = self.session.post(aimUrl, data=data, headers=getLibHeader()).json()
258 | ans = r['examQuestion']['answer']
259 | self.json.append({"question": each, "answer": ans})
260 | if total == len(self.questionList):
261 | self.__ifCorrect()
262 | else:
263 | print("[*] 已经更新题库,开始新的一轮答题")
264 | except Exception as e:
265 | raise Exception(f"getAns 发生错误:{e}")
266 |
267 | def run(self):
268 | times = 0
269 | while self.step < 6:
270 | if times >= 9:
271 | raise Exception("尝试过多次数")
272 | times += 1
273 | self.__getJumpUrl()
274 | try:
275 | self.__judgeStep()
276 | self.__getStart()
277 | self.__getAns()
278 | except Exception as e:
279 | print(f"发生错误 {e}")
280 |
281 |
282 | if __name__ == "__main__":
283 | print("[*] 更多信息:https://github.com/HengY1Sky/Jnu-ToolsBox")
284 | print("[*] 使用方法:请先到 https://libtrain.jnu.edu.cn/ 进入学习闯关")
285 | print("[*] 使用方法:之后点击跳过并进入答题激活您是初中生即可,之后填写账号密码于此运行")
286 | account, password = "", ""
287 | GetRootPass(account, password).run()
288 |
--------------------------------------------------------------------------------
/图书馆借阅快速答题/QA.json:
--------------------------------------------------------------------------------
1 | [
2 | {"question": "41dc0bd0-0f8d-4910-98ba-2fe406ddc823", "answer": "69b6d5e3-f02c-4ef0-9d6e-05d844fa2044"},
3 | {"question": "bdaf33eb-94be-4f2a-b368-e33faccd876f", "answer": "8e729d85-8512-4272-8fcd-e8d37d69d8a7"},
4 | {"question": "4d45e8bc-04d9-40a5-8c49-5851ce6f4f97", "answer": "937d801e-3d3d-4f5d-9dde-567142605594"},
5 | {"question": "8300b24b-bf35-4566-96ce-b8283a8e51a5", "answer": "e054ed0a-8df4-42bf-a23b-20e8a43a802f,ac10128f-2d60-4539-bc19-576277953005,0a590078-6ba2-46f7-8cbc-1230fa2e2492,cba8bac3-6682-4e0e-baf2-97199bd97a8d"},
6 | {"question": "77943025-3256-422d-a18b-bbf3688d7538", "answer": "d75d2337-0b67-4164-84ae-9ac7eb200b37,54a75e22-0a0b-40f8-8e89-e884e62c8a28,0364cc00-e4e3-4527-b28b-cee7b66de419,8f287082-ada2-499f-a5fa-ef5bc1da9066"},
7 | {"question": "255e6030-372a-4b3e-b416-7f2234b3447a", "answer": "9d4a6660-91d2-46c6-b0be-52805beadf6e"},
8 | {"question": "8c9cf2cd-3b92-4304-baaf-b0ba260c539f", "answer": "e211b368-69e9-42f3-9db2-315928735ad5"},
9 | {"question": "f2f7d4c0-ffd5-41f4-8a7a-1c621ac9564a", "answer": "34e97b67-f9f5-4d38-ba7e-e857dc915b6b"},
10 | {"question": "def36773-d6b5-46db-815b-12f3d0cd3b0b", "answer": "dca31d82-34b8-420c-b63f-78cd38379ba4,8c006efd-aaf2-4388-a40c-18916603d11d"},
11 | {"question": "45ee3023-2a44-44a2-884d-b5e89b80c234", "answer": "4e82d9f6-d605-4e22-8294-44657cdbec2f"},
12 | {"question": "102460cd-262f-4862-a181-3d8da33f2be8", "answer": "c5421546-cfd0-4596-8f32-70eacfd4eb09"},
13 | {"question": "ba21f4b2-0bd8-4967-b4ee-1056034f482e", "answer": "fa13e27c-238e-4bdd-9ecb-e48b1dc5138c"},
14 | {"question": "be504702-2516-47ab-a390-d86cb3bbd86e", "answer": "c920b184-f560-4527-a384-baf818099611,d26449f1-e306-4bb4-a536-41ad05808fb4,79deb24f-fba0-4cfe-a7e9-4f4d17468673,823d067f-e70b-4b5e-aa26-13916c89398d"},
15 | {"question": "44166982-40f1-47a7-ac75-aac35565ad24", "answer": "21281784-df67-4bc3-9230-d55e37b324b5"},
16 | {"question": "3f03350f-fb60-4f28-8a93-1c8b9d8c3696", "answer": "59f181b1-c943-4a6c-9140-71eb21d647e6"},
17 | {"question": "01071115-9e58-4eeb-ab9f-6e76b1735d40", "answer": "4307b517-6d81-4582-8c85-798fc4bcfb98"},
18 | {"question": "391a8442-8f72-4a83-98fb-f209d722fb46", "answer": "d63160e1-0df7-425a-8bcb-ecc1bfcb0c75"},
19 | {"question": "d1c154b5-fa37-49d0-b62c-995769a03ff0", "answer": "9344278f-5d06-4307-87c1-735f9655a14e,c3fa6bd6-5654-41b5-aef1-720d73e01ad2,7884f3ef-0d81-406e-8d61-c62247e2ef78,5d149fb6-21fe-4ff2-86ec-2a7829434958"},
20 | {"question": "832df1f7-2979-42b2-a189-0472c99fb74c", "answer": "16e0dd57-8472-4c86-aadd-68f323cd4606,3dc4e463-0cc5-46e0-8340-d643dc41abae"},
21 | {"question": "74eac17f-ee52-4a25-8b81-194a56845079", "answer": "0def2cdd-b365-4920-91a8-1671e021254e,eddfe1fd-137f-4662-a370-db0d6b59f577"},
22 | {"question": "2740ff4a-2a0b-40c6-8024-52954297fa6b", "answer": "ee6c23c5-1eb2-4bf6-a337-d53b1b4bf321,1d633ad4-863f-4380-8c60-5faa4bfbfcfe,8cd67cea-8547-47ba-a6e1-9629d5b717ad,a7d01b60-8279-4a99-bf78-afc2cf6f40d8"},
23 | {"question": "efb95298-7ebd-4ec1-891c-ab1c829875b6", "answer": "fd9e9842-b02e-49b7-874f-a999c1e3639d"},
24 | {"question": "1552c904-53f4-4277-92e4-f17ac9727623", "answer": "6d939e61-60b1-43e8-b4d4-b78f1a7cbe83"},
25 | {"question": "343af6d5-c187-40a6-96cc-761f2a4a0548", "answer": "039a88b7-7bd6-46e6-be81-d1411bb4d6b4"},
26 | {"question": "56f339d5-2b9d-4a5a-a666-53e2f44f56e9", "answer": "3d42e476-07b9-4086-aef2-1ff6d60b3227"},
27 | {"question": "aa9f23ec-c243-4580-963d-d5e006b03b58", "answer": "8b6b70cd-ad15-4ca1-a644-c767bb0c7e6f"},
28 | {"question": "febe2af1-321b-47cd-be32-9db04297542a", "answer": "37537bf2-b427-4202-9a79-72aef5fcd3f7,ccad0411-43ab-4248-8829-69bd9dc6f995,d85f33cb-1aa2-4563-bb70-1ab113e9444b,fed64551-ebb8-4538-8935-b3b738341f4c"},
29 | {"question": "0a23d14d-dddb-430c-90fe-aec8ba4802aa", "answer": "40673512-0b42-4cfe-9032-25ceb6ed4c86,ee8003c9-01ad-48d9-85d3-e4e5ffb470b5,e806889e-03e2-4952-bc7d-ffe7bf18389f,e44fc5d2-5b9e-41d0-80ac-1f4dc93f1a3b"},
30 | {"question": "0b548f98-1a9d-44db-a476-a9e81184e5e2", "answer": "aebe2f5f-3a1e-40d0-9227-2dda02ee684a"},
31 | {"question": "97ed8b8b-a18c-448d-9896-d2e7f7d491c6", "answer": "8e2f9961-f30d-44f9-aadb-b55349e82998"},
32 | {"question": "bb65d35c-2939-408b-be9e-0a3c4ef7bb12", "answer": "259ea7d4-9f56-4bc3-87cb-8993fe9d5431"},
33 | {"question": "777c94ea-a85c-4a86-beb7-5dbaab491513", "answer": "ce39961a-ed05-4989-9d27-b147f864320a,10580805-c942-4830-ae4c-e2e0d6c666e6,787fe528-bc36-45af-93a8-41b4cd69a4c4,1fab2270-397c-41c4-abf4-b6cc22877744"},
34 | {"question": "2386447e-0a25-48d3-b985-9c2fdab278bd", "answer": "ccde2792-0469-4b25-9c8b-45ea3f7e0201"},
35 | {"question": "f03bb704-08e0-48fa-a498-76348cc15ced", "answer": "6aa5ddb5-f31c-4e50-b9e8-9213bb459abf"},
36 | {"question": "82ac47eb-e92a-43e2-b1e1-d001908da116", "answer": "a8c7d42a-5765-4f8a-914c-ea06e497fee6"},
37 | {"question": "c00f3a06-d8f6-4f5f-9a3c-42a2c5e3904e", "answer": "7d53b3d3-795e-41fb-a950-5f2ef17ed339,c4fe0b07-4b7e-451b-89f2-98b8d23f478b,87c66411-551c-4e25-917b-661f7137c36b,8b03804f-3219-4b43-8183-d55ec6df076a"},
38 | {"question": "c2fc3a7b-fc9f-44ef-b2a1-29c9d1354524", "answer": "d182d67d-2da7-4a7a-a81b-66bfd0a495df"},
39 | {"question": "a16e523c-4ff7-472e-b507-9002e6066cad", "answer": "19b31f64-d906-4499-92ac-060a322429b1"},
40 | {"question": "b3f39a6b-a732-4fe4-a95a-6e4e78c261be", "answer": "602b4daa-0d64-444c-a5e6-800edbc08392,f5c2a2ac-5422-467b-a008-231a328b4b6b,b9e576cc-8367-4bdf-821f-e85dddd094fb,a3de5501-8568-4738-a7ca-878665d73c71"},
41 | {"question": "e52817dc-017c-4f1a-bb31-74f6daff320f", "answer": "6aaab9ad-14b3-4cd6-8c98-cf9e3673ea42,dda600ba-a7e4-4f03-b030-46502e137a5e,8f597963-0399-4710-9aca-4b65ec1ba7dd,a7035555-c927-44bb-a9b7-ffb734a4abf0"},
42 | {"question": "a34f0b7a-7aa6-420d-889f-7cbcd40cdd29", "answer": "c729bf58-78e4-4003-a009-711aacbf00c1"},
43 | {"question": "bc00fe55-351f-4067-828a-9aa383906f0a", "answer": "5e534241-df52-4a1a-9486-d0b8d603514b"},
44 | {"question": "7edcfa85-558c-45f7-95d5-df6d51951334", "answer": "aeecf6ef-1f32-4729-8a23-ed3e032fa8f6"},
45 | {"question": "ac850769-1e4d-497f-b69f-3a805955be72", "answer": "c8f945b0-f4f1-420a-a7a9-4262c8d545af,0fc9dbcf-e066-4069-b6bb-e5148727c1e9,c914100e-4468-4021-aa58-4f7405db357d,118e7f51-7975-4d56-85a7-cbd166615483"},
46 | {"question": "7854f01a-5d79-4c81-83c4-0d6353da5693", "answer": "3984ddad-d6d9-4c1b-95ea-291368b567aa,0df9c7ae-d9a2-4b4c-a359-be01e62fb772,90e204e2-644c-488d-8645-baec516a9eec,665b2eac-d3d4-4678-9341-c25192fcabfb"},
47 | {"question": "9f7514b4-c0a0-4ac1-8d6e-362a318ed6e6", "answer": "bc13c49a-bcdb-4929-92c2-cdef5eebd598,520a1e05-fb64-41b3-8bd1-33c25a50a73e"},
48 | {"question": "b0e7b2a8-0afc-47e3-be94-0d4ce5fe5d5a", "answer": "e17161b4-6a91-4cd3-a17b-7c4f9c203ee9"},
49 | {"question": "edcc752c-bfd6-4d72-93a3-5f78fe32045c", "answer": "c80c8456-235b-4b93-868b-0ea6bfe863fb"},
50 | {"question": "12ab23a0-ccb9-461b-aa0f-e80ee7f078d2", "answer": "134dde7e-8484-48fa-8325-08e96312e0ae,0a4cfa72-bb4b-4cb5-9918-cf675e20c7b2,0ecbc30e-b19b-4640-b5bc-af5e92a83f9d,d43735e1-ede3-4e36-ac6a-203265230b38"},
51 | {"question": "d5a51712-9fa3-4666-aa1b-5ff33f128c54", "answer": "b3aa353f-b3e7-45a2-a4e4-1e2506aed5df,b05ec7cf-4302-496a-af03-4db13fce84f5,afee7569-3c05-4786-9bc6-e07177782df6,230cae55-b6df-4460-b1e6-b8cee0b982ad"},
52 | {"question": "fa8b8f5c-76d1-42a8-a21a-4fecc7708da5", "answer": "344a6ba9-2dfa-4226-a25c-119240122299"},
53 | {"question": "9aadce1d-a383-4480-92c9-e82bcd84e62d", "answer": "6c9148c6-6841-4c01-8bc6-1e350b0c0daf"},
54 | {"question": "407c8652-f082-4e5c-8ecc-08c2fba1168d", "answer": "c9c1c98b-5e34-484c-895e-f4b0d994635a"},
55 | {"question": "42e9570a-1ee0-4e9f-ba50-27e5030ed93a", "answer": "57c40ebe-cc9a-4e6d-9a25-b4fc1ef35922,eb0c73a3-ab49-4227-9f58-8a51d72c3d20,7387a731-209e-4f9f-91a4-f2ebb2f0c82c,0d7ce7c6-b30a-4d20-8cc8-36577ef5d41c"},
56 | {"question": "6c1864bf-f648-4914-ae34-842c3dfce0a1", "answer": "a4979de2-452b-4b38-98a8-174a4106a1dc,51b3ee9b-027b-483d-bd17-2080d09d9e95,b1038604-0ffa-4062-9559-ade62279fe18,44e6a14a-39d4-4b76-989a-262e74271312"},
57 | {"question": "ba42a14e-3648-4849-b91a-8a2709a13f3f", "answer": "5215e5b6-6cc5-4d6e-9493-90c395803f6b,2de4f871-c0ca-4e8d-8fc5-bad5328fffaa"},
58 | {"question": "1157770b-96a5-4054-bf8f-62ace2b39863", "answer": "6d435fa3-e543-4fb2-af15-61104692cf65,c75eb1fc-5559-49d2-ba1c-945c7a854b11,98532d61-e892-40ba-8575-d973679393ac,cb29a870-ef07-42e2-9c29-0a24ed4a0303"},
59 | {"question": "57aba38b-b0b4-4215-be79-d77408b5b237", "answer": "f2ccac8d-8bec-4ccf-9b71-5e0614bdc885,24089689-dde4-4c6c-8305-bcc9fc027c62,23eeedad-4298-4641-94a3-c83844ec031f,b6397a15-7c03-4534-aef5-ae76ea19a758"},
60 | {"question": "9391c6ec-35f5-4f81-be45-e9abfdd5e640", "answer": "2ad90c81-2400-43c4-a782-8af0162754da"},
61 | {"question": "5173d7fd-5ce9-478a-8421-a1a69524e025", "answer": "880e321a-16fc-4553-a088-8ef5172127e7"},
62 | {"question": "984fe2b1-9930-4f72-a413-91dde1f1da33", "answer": "1219bbfe-8dad-4c07-9459-41dbea395410,acbecb36-497a-4bfb-8817-4d484a54d94c,796f06e2-bc48-4ec6-80e5-4b3dff8b37b3,9851eea3-4d38-4e52-bdf4-037052f66685"},
63 | {"question": "ddde6160-1303-46a4-904c-bac2d877e727", "answer": "915bbef8-784a-4eb1-9bd5-deb11edd3d08,926c5057-d670-4c35-81b4-423afe9b28a1,5b33141a-2388-49f1-9f6d-83d397464a13"},
64 | {"question": "926d7970-83fc-44de-a1c3-895de8d8bebe", "answer": "c56aa070-1616-4497-9551-d2f7cbb01abc"},
65 | {"question": "78c61642-d44b-4c8f-94ee-168d24176e3a", "answer": "2653fb7e-1777-4a20-b63b-e8f2d2b3bd3e"},
66 | {"question": "60d51fbf-5c71-4dcd-9d8b-7113633831a5", "answer": "84eef778-cecb-4004-8abf-aad9a60290b8,5d69129e-d145-436f-b9b4-3e9a7e5aa40c,7075a7f1-75bc-499f-8471-6a979f9831f7,19a8734f-e4c2-4b91-9fe2-f928b4e24b01"},
67 | {"question": "b7c7c958-236f-4db9-89cb-daba615cd06d", "answer": "c58e9cad-2737-4875-8176-ccb72789e93b,6a73ee48-3eb7-4b2e-8d64-83509d1900d6,9a6ea59c-a481-4e73-834c-e6edcbc10486,331fee21-8e89-4f38-b67d-759340355a85"},
68 | {"question": "4dda5af9-f942-483b-84f0-62040f35c77c", "answer": "2ca8bc11-d9bb-4260-94f4-baa1b50a8eeb,d52ccd34-a296-44b0-b8cf-48cebdceaf79,185bebb9-8180-45de-b938-130e425120f3"},
69 | {"question": "cb257e51-bbb4-4f92-bdc1-f295948395b1", "answer": "578288c7-14ea-42f9-92e7-c5d2b186c7f7"},
70 | {"question": "455011b8-cee2-459e-9653-39fe95e42e17", "answer": "a2ddd228-24ca-447d-89a2-beee0c1601bc"},
71 | {"question": "ba246e01-4b22-4421-a0b8-9010a7fd1371", "answer": "fd03401a-4ec2-48c7-9c1b-298f2df67ed3,190854f2-ca3e-4e82-ab0e-a42fd92f603b,908c4539-6dea-4ddf-98cf-30ee4a2e7976,bec172e8-5368-4d7c-9171-4558c4593c9f"},
72 | {"question": "d5ce913f-e5fd-4570-9593-b5586df91566", "answer": "ff7b9f0d-aa17-4fb3-accc-9d9ef209a492"},
73 | {"question": "8030fc5b-225b-4dc6-8f52-d6ac2ac618d1", "answer": "08929402-0f84-4215-9f8e-b46637a4f48b,8859529a-8eb5-4676-b443-b12c0c193498,2fe8751b-2626-4be5-a997-8448ead51dc6,df0710d0-b3a7-42f2-8c0b-31b3668c2c85"},
74 | {"question": "be8808ac-ecf3-4987-81a6-01cc86b60d0c", "answer": "66c1f02d-3191-48a0-948a-30bbe7813b0e,69e17f60-62f3-43db-850b-8f4ee930115f"},
75 | {"question": "962101cb-b32d-45e8-87b2-ef26154ff5f4", "answer": "4c9a15e5-a69f-4dd1-a226-d1e25fc3e8b3"},
76 | {"question": "8403aa7b-f4f2-4592-9db0-39f6a7438bff", "answer": "8126e8d6-565c-48a5-8d26-5a4b0687e9cd,ad8682a2-34c2-4ade-86f1-134485b92772,e19abd5b-ffea-4945-969f-a816bcbf3694"},
77 | {"question": "d15527aa-73e3-47b8-8ded-764688bcadfd", "answer": "5a9292eb-9a85-402a-883f-e0d415e909fb,d9a657d8-a95e-4bfd-b47d-e2560943503f,50fe4a4a-4e34-4bbd-86e8-fe8b86b693ca,a5557ce4-c9fa-4f9d-957b-06602c3a7dd2"},
78 | {"question": "e4d375d4-f251-4634-b4c7-095f3ba5df58", "answer": "abb3f4ce-b868-49c0-893c-4931e485d917,c8da147f-27e3-4056-bc7a-9bab75e5c3f9"},
79 | {"question": "3f7424ba-d00e-4b4e-8f00-9d0e0e96e41c", "answer": "2ed3da81-6963-46da-a805-dd140355c4d5"},
80 | {"question": "29335b66-a832-4731-8ee1-8cb9de769127", "answer": "44dd8f6c-aed0-4357-8726-f5f520eed227"},
81 | {"question": "52c5ff08-b7f7-4c84-a8a0-48cced3beacc", "answer": "f3486cd8-67b7-4a52-be9b-31294e32556c,5e00f961-ccbd-46e9-8a54-26722319061e,4ce40f3e-5e37-4df8-a004-163df88f9940,ab8ad53f-2478-46c7-90d2-e7ae3a19c195"},
82 | {"question": "295a10c2-a557-45dc-9814-81dd78ff397c", "answer": "cf3c0605-9116-4ee6-8d64-7fcb85d9deb8,c4fa6a4b-f4ae-4783-963b-c75e5e271fad,c09a2db9-4d9b-46bd-8f78-c727ddd5c020"},
83 | {"question": "f20e2506-eb1c-4448-a7a1-17bc7a249de5", "answer": "b346c0a3-e902-4b9f-b0ce-a03ce76f3b0c,8b7dac33-65af-4e12-b9c8-324b6dfee6cc,69929721-290a-4cd6-a2b5-8f80b76ac45a,042cd3b3-1093-4214-9dd2-bda5afbafc4d"},
84 | {"question": "98399018-635d-4026-abcc-50cd3d4843ee", "answer": "e425d925-5802-4a0d-a18f-1468f4dd09e2"},
85 | {"question": "439a9bc9-3014-4f8c-91b1-ef7305662223", "answer": "4f712e94-0d8b-4664-a34d-a5e344b20e35"},
86 | {"question": "4c127806-220b-4da1-b9ee-0821e58dd1d8", "answer": "91541205-4a9b-43b1-887c-46932c424edd,460293a0-2ad4-419b-abaa-c9841c1c8436"},
87 | {"question": "c89cd216-4354-42ea-958e-aa32e4de701c", "answer": "0c283f19-8ffb-49d9-97c0-dc7811a0dab3,f864da25-5df8-43bf-a8df-b9ccf665498d,4593e7a7-583c-4e48-a732-eaab6fd1c71f,915af8a4-ab68-4f93-bd2f-10346af53bde"},
88 | {"question": "d535feed-8c25-4ee5-8571-dbc5b2ed2511", "answer": "f23fac9c-c65d-4808-9c74-60e7669d91f6,6d4424f2-8faf-41e1-9b22-ba4fdb54d6cb,969354e0-19a5-4257-8e5f-52aafd817e86"},
89 | {"question": "8ab90152-4b17-45da-b61c-67c88a1bd8fb", "answer": "7b1cd4b5-6c23-4ad8-8853-5bceb662ee46,7cf0f1b4-7646-4c37-bbbb-6a35730bcb1a,b9fb1978-7537-4c0f-a1a5-d4d9cd47f177,b7bff384-2967-4cd8-9ba1-11977a2a4dfe"},
90 | {"question": "319725d5-73bb-49f7-9d39-1992340083ce", "answer": "8f89ce45-a920-49a2-b841-4f8bd8c0db95"},
91 | {"question": "8065c5bf-1714-4bd7-a9d9-cbec084483de", "answer": "c1660b40-1707-485b-af94-01c4ed78dc67,0252c577-4a1f-4294-9b17-59d000379010,2064708a-3d44-4685-8e4c-5909c88d8701,92eb1dad-3736-4d35-8994-5cefab217177"},
92 | {"question": "4d4cfa0e-1f0f-440d-ab1c-5262053c6077", "answer": "a32e1eb4-44ce-4c00-80f2-9a335bb73b71"},
93 | {"question": "956e9b9d-6776-4977-b4b4-a90433efeb23", "answer": "7806997e-5dbd-4d4f-8b79-e5bbd30ef75d"},
94 | {"question": "a3209c88-3679-4b7f-8b27-aa5923ce63b4", "answer": "2d4badf8-f168-470f-92c1-9bba39377765,b949b810-fb00-4431-9abe-1c11bea8d786,33f6dc7b-be51-4203-8966-f03edef715cd"},
95 | {"question": "1c2cce97-502d-42c9-bf73-5dc53a0858ba", "answer": "79961ce7-dda0-4ea9-8f4b-7bd6a7b14033"},
96 | {"question": "430af63f-ecee-43ca-bf6d-d673a5525d21", "answer": "7a7a89b7-6c48-4aa7-b476-b31c1344e23c"},
97 | {"question": "f775bc3a-2bd9-40e5-b824-ff59ca13b0cf", "answer": "75318ec9-f2f2-4372-8e56-cad35c5fc795,a2cb4eaa-cc24-47d6-85aa-7d2e2c4878c2"},
98 | {"question": "f43402c0-fb8c-49c0-9d6a-84482df810a2", "answer": "4a0787d9-8ef5-492c-aae0-cc331fb119ff,7ca6de04-7688-4c01-b4bc-8a3c12e929ce,96c1275a-9530-4e29-84db-7bf4c9229151,6a45f3de-ca85-41b1-a75c-42c175e53409"},
99 | {"question": "6c586b8a-4597-4d15-ba5e-fcaa82c02ebf", "answer": "4200d144-2ce3-4c8e-84a8-dc95972db58e,46ef43f2-05fb-41f8-844b-3aa22549fc3c,a1bb8ccc-09c4-45fe-ba81-3b25bfe3ac0a,fc943de3-ac4e-42a1-966a-fa3fd5f44498"},
100 | {"question": "24466e23-a04f-4e92-bd1c-e20430fcd009", "answer": "825b9ea4-c523-4189-a945-c85d84d9cedf,4bead9e6-4da3-453c-8812-5588a84c5882,f8092e6f-b768-41f7-8b54-d216cd0c4c50,e30c8821-6e2d-430d-bf6d-dd0cc4afe566"},
101 | {"question": "1367e849-51b5-48db-9bb8-becb69fa9de0", "answer": "5158ec3c-5640-4e91-9c7d-e001d7796a73"},
102 | {"question": "1cfe9453-265b-4fed-9c0d-702412bd38d2", "answer": "3abcadf3-5552-4c5c-a3d7-a9b6ba295046"},
103 | {"question": "cfe43706-4918-4108-aae9-b84a70543f8b", "answer": "9ad7306d-705f-44fb-b532-a14c95003c34"},
104 | {"question": "35bc26c8-2a57-43e9-93ff-fb6215075ab0", "answer": "8b530327-6e8e-4561-af6f-6be171b87104"},
105 | {"question": "c8d96b4a-096d-4a87-a18b-991d4a9ed2e3", "answer": "04319093-b9d3-42a5-9580-9dba0d36445b"},
106 | {"question": "80acdb8b-0396-4df6-8aaf-805a389ae14e", "answer": "c8cc451e-6458-4abd-8eaa-1081fb1beec7"},
107 | {"question": "39419f28-e204-4e9d-bfc6-1abd91435b34", "answer": "eee7c547-5ebc-423a-8f5d-c1897d2174c7"}
108 | ]
109 |
--------------------------------------------------------------------------------
/图书馆借阅快速答题/des.js:
--------------------------------------------------------------------------------
1 | /**
2 | * DES加密解密
3 | * @Copyright Copyright (c) 2006
4 | * @author Guapo
5 | * @see DESCore
6 | */
7 |
8 | /*
9 | * encrypt the string to string made up of hex
10 | * return the encrypted string
11 | */
12 | function strEnc(data,firstKey,secondKey,thirdKey){
13 |
14 | var leng = data.length;
15 | var encData = "";
16 | var firstKeyBt,secondKeyBt,thirdKeyBt,firstLength,secondLength,thirdLength;
17 | if(firstKey != null && firstKey != ""){
18 | firstKeyBt = getKeyBytes(firstKey);
19 | firstLength = firstKeyBt.length;
20 | }
21 | if(secondKey != null && secondKey != ""){
22 | secondKeyBt = getKeyBytes(secondKey);
23 | secondLength = secondKeyBt.length;
24 | }
25 | if(thirdKey != null && thirdKey != ""){
26 | thirdKeyBt = getKeyBytes(thirdKey);
27 | thirdLength = thirdKeyBt.length;
28 | }
29 |
30 | if(leng > 0){
31 | if(leng < 4){
32 | var bt = strToBt(data);
33 | var encByte ;
34 | if(firstKey != null && firstKey !="" && secondKey != null && secondKey != "" && thirdKey != null && thirdKey != ""){
35 | var tempBt;
36 | var x,y,z;
37 | tempBt = bt;
38 | for(x = 0;x < firstLength ;x ++){
39 | tempBt = enc(tempBt,firstKeyBt[x]);
40 | }
41 | for(y = 0;y < secondLength ;y ++){
42 | tempBt = enc(tempBt,secondKeyBt[y]);
43 | }
44 | for(z = 0;z < thirdLength ;z ++){
45 | tempBt = enc(tempBt,thirdKeyBt[z]);
46 | }
47 | encByte = tempBt;
48 | }else{
49 | if(firstKey != null && firstKey !="" && secondKey != null && secondKey != ""){
50 | var tempBt;
51 | var x,y;
52 | tempBt = bt;
53 | for(x = 0;x < firstLength ;x ++){
54 | tempBt = enc(tempBt,firstKeyBt[x]);
55 | }
56 | for(y = 0;y < secondLength ;y ++){
57 | tempBt = enc(tempBt,secondKeyBt[y]);
58 | }
59 | encByte = tempBt;
60 | }else{
61 | if(firstKey != null && firstKey !=""){
62 | var tempBt;
63 | var x = 0;
64 | tempBt = bt;
65 | for(x = 0;x < firstLength ;x ++){
66 | tempBt = enc(tempBt,firstKeyBt[x]);
67 | }
68 | encByte = tempBt;
69 | }
70 | }
71 | }
72 | encData = bt64ToHex(encByte);
73 | }else{
74 | var iterator = parseInt(leng/4);
75 | var remainder = leng%4;
76 | var i=0;
77 | for(i = 0;i < iterator;i++){
78 | var tempData = data.substring(i*4+0,i*4+4);
79 | var tempByte = strToBt(tempData);
80 | var encByte ;
81 | if(firstKey != null && firstKey !="" && secondKey != null && secondKey != "" && thirdKey != null && thirdKey != ""){
82 | var tempBt;
83 | var x,y,z;
84 | tempBt = tempByte;
85 | for(x = 0;x < firstLength ;x ++){
86 | tempBt = enc(tempBt,firstKeyBt[x]);
87 | }
88 | for(y = 0;y < secondLength ;y ++){
89 | tempBt = enc(tempBt,secondKeyBt[y]);
90 | }
91 | for(z = 0;z < thirdLength ;z ++){
92 | tempBt = enc(tempBt,thirdKeyBt[z]);
93 | }
94 | encByte = tempBt;
95 | }else{
96 | if(firstKey != null && firstKey !="" && secondKey != null && secondKey != ""){
97 | var tempBt;
98 | var x,y;
99 | tempBt = tempByte;
100 | for(x = 0;x < firstLength ;x ++){
101 | tempBt = enc(tempBt,firstKeyBt[x]);
102 | }
103 | for(y = 0;y < secondLength ;y ++){
104 | tempBt = enc(tempBt,secondKeyBt[y]);
105 | }
106 | encByte = tempBt;
107 | }else{
108 | if(firstKey != null && firstKey !=""){
109 | var tempBt;
110 | var x;
111 | tempBt = tempByte;
112 | for(x = 0;x < firstLength ;x ++){
113 | tempBt = enc(tempBt,firstKeyBt[x]);
114 | }
115 | encByte = tempBt;
116 | }
117 | }
118 | }
119 | encData += bt64ToHex(encByte);
120 | }
121 | if(remainder > 0){
122 | var remainderData = data.substring(iterator*4+0,leng);
123 | var tempByte = strToBt(remainderData);
124 | var encByte ;
125 | if(firstKey != null && firstKey !="" && secondKey != null && secondKey != "" && thirdKey != null && thirdKey != ""){
126 | var tempBt;
127 | var x,y,z;
128 | tempBt = tempByte;
129 | for(x = 0;x < firstLength ;x ++){
130 | tempBt = enc(tempBt,firstKeyBt[x]);
131 | }
132 | for(y = 0;y < secondLength ;y ++){
133 | tempBt = enc(tempBt,secondKeyBt[y]);
134 | }
135 | for(z = 0;z < thirdLength ;z ++){
136 | tempBt = enc(tempBt,thirdKeyBt[z]);
137 | }
138 | encByte = tempBt;
139 | }else{
140 | if(firstKey != null && firstKey !="" && secondKey != null && secondKey != ""){
141 | var tempBt;
142 | var x,y;
143 | tempBt = tempByte;
144 | for(x = 0;x < firstLength ;x ++){
145 | tempBt = enc(tempBt,firstKeyBt[x]);
146 | }
147 | for(y = 0;y < secondLength ;y ++){
148 | tempBt = enc(tempBt,secondKeyBt[y]);
149 | }
150 | encByte = tempBt;
151 | }else{
152 | if(firstKey != null && firstKey !=""){
153 | var tempBt;
154 | var x;
155 | tempBt = tempByte;
156 | for(x = 0;x < firstLength ;x ++){
157 | tempBt = enc(tempBt,firstKeyBt[x]);
158 | }
159 | encByte = tempBt;
160 | }
161 | }
162 | }
163 | encData += bt64ToHex(encByte);
164 | }
165 | }
166 | }
167 | return encData;
168 | }
169 |
170 | /*
171 | * decrypt the encrypted string to the original string
172 | *
173 | * return the original string
174 | */
175 | function strDec(data,firstKey,secondKey,thirdKey){
176 | var leng = data.length;
177 | var decStr = "";
178 | var firstKeyBt,secondKeyBt,thirdKeyBt,firstLength,secondLength,thirdLength;
179 | if(firstKey != null && firstKey != ""){
180 | firstKeyBt = getKeyBytes(firstKey);
181 | firstLength = firstKeyBt.length;
182 | }
183 | if(secondKey != null && secondKey != ""){
184 | secondKeyBt = getKeyBytes(secondKey);
185 | secondLength = secondKeyBt.length;
186 | }
187 | if(thirdKey != null && thirdKey != ""){
188 | thirdKeyBt = getKeyBytes(thirdKey);
189 | thirdLength = thirdKeyBt.length;
190 | }
191 |
192 | var iterator = parseInt(leng/16);
193 | var i=0;
194 | for(i = 0;i < iterator;i++){
195 | var tempData = data.substring(i*16+0,i*16+16);
196 | var strByte = hexToBt64(tempData);
197 | var intByte = new Array(64);
198 | var j = 0;
199 | for(j = 0;j < 64; j++){
200 | intByte[j] = parseInt(strByte.substring(j,j+1));
201 | }
202 | var decByte;
203 | if(firstKey != null && firstKey !="" && secondKey != null && secondKey != "" && thirdKey != null && thirdKey != ""){
204 | var tempBt;
205 | var x,y,z;
206 | tempBt = intByte;
207 | for(x = thirdLength - 1;x >= 0;x --){
208 | tempBt = dec(tempBt,thirdKeyBt[x]);
209 | }
210 | for(y = secondLength - 1;y >= 0;y --){
211 | tempBt = dec(tempBt,secondKeyBt[y]);
212 | }
213 | for(z = firstLength - 1;z >= 0 ;z --){
214 | tempBt = dec(tempBt,firstKeyBt[z]);
215 | }
216 | decByte = tempBt;
217 | }else{
218 | if(firstKey != null && firstKey !="" && secondKey != null && secondKey != ""){
219 | var tempBt;
220 | var x,y,z;
221 | tempBt = intByte;
222 | for(x = secondLength - 1;x >= 0 ;x --){
223 | tempBt = dec(tempBt,secondKeyBt[x]);
224 | }
225 | for(y = firstLength - 1;y >= 0 ;y --){
226 | tempBt = dec(tempBt,firstKeyBt[y]);
227 | }
228 | decByte = tempBt;
229 | }else{
230 | if(firstKey != null && firstKey !=""){
231 | var tempBt;
232 | var x,y,z;
233 | tempBt = intByte;
234 | for(x = firstLength - 1;x >= 0 ;x --){
235 | tempBt = dec(tempBt,firstKeyBt[x]);
236 | }
237 | decByte = tempBt;
238 | }
239 | }
240 | }
241 | decStr += byteToString(decByte);
242 | }
243 | return decStr;
244 | }
245 | /*
246 | * chang the string into the bit array
247 | *
248 | * return bit array(it's length % 64 = 0)
249 | */
250 | function getKeyBytes(key){
251 | var keyBytes = new Array();
252 | var leng = key.length;
253 | var iterator = parseInt(leng/4);
254 | var remainder = leng%4;
255 | var i = 0;
256 | for(i = 0;i < iterator; i ++){
257 | keyBytes[i] = strToBt(key.substring(i*4+0,i*4+4));
258 | }
259 | if(remainder > 0){
260 | keyBytes[i] = strToBt(key.substring(i*4+0,leng));
261 | }
262 | return keyBytes;
263 | }
264 |
265 | /*
266 | * chang the string(it's length <= 4) into the bit array
267 | *
268 | * return bit array(it's length = 64)
269 | */
270 | function strToBt(str){
271 | var leng = str.length;
272 | var bt = new Array(64);
273 | if(leng < 4){
274 | var i=0,j=0,p=0,q=0;
275 | for(i = 0;ij;m--){
280 | pow *= 2;
281 | }
282 | bt[16*i+j]=parseInt(k/pow)%2;
283 | }
284 | }
285 | for(p = leng;p<4;p++){
286 | var k = 0;
287 | for(q=0;q<16;q++){
288 | var pow=1,m=0;
289 | for(m=15;m>q;m--){
290 | pow *= 2;
291 | }
292 | bt[16*p+q]=parseInt(k/pow)%2;
293 | }
294 | }
295 | }else{
296 | for(i = 0;i<4;i++){
297 | var k = str.charCodeAt(i);
298 | for(j=0;j<16;j++){
299 | var pow=1;
300 | for(m=15;m>j;m--){
301 | pow *= 2;
302 | }
303 | bt[16*i+j]=parseInt(k/pow)%2;
304 | }
305 | }
306 | }
307 | return bt;
308 | }
309 |
310 | /*
311 | * chang the bit(it's length = 4) into the hex
312 | *
313 | * return hex
314 | */
315 | function bt4ToHex(binary) {
316 | var hex;
317 | switch (binary) {
318 | case "0000" : hex = "0"; break;
319 | case "0001" : hex = "1"; break;
320 | case "0010" : hex = "2"; break;
321 | case "0011" : hex = "3"; break;
322 | case "0100" : hex = "4"; break;
323 | case "0101" : hex = "5"; break;
324 | case "0110" : hex = "6"; break;
325 | case "0111" : hex = "7"; break;
326 | case "1000" : hex = "8"; break;
327 | case "1001" : hex = "9"; break;
328 | case "1010" : hex = "A"; break;
329 | case "1011" : hex = "B"; break;
330 | case "1100" : hex = "C"; break;
331 | case "1101" : hex = "D"; break;
332 | case "1110" : hex = "E"; break;
333 | case "1111" : hex = "F"; break;
334 | }
335 | return hex;
336 | }
337 |
338 | /*
339 | * chang the hex into the bit(it's length = 4)
340 | *
341 | * return the bit(it's length = 4)
342 | */
343 | function hexToBt4(hex) {
344 | var binary;
345 | switch (hex) {
346 | case "0" : binary = "0000"; break;
347 | case "1" : binary = "0001"; break;
348 | case "2" : binary = "0010"; break;
349 | case "3" : binary = "0011"; break;
350 | case "4" : binary = "0100"; break;
351 | case "5" : binary = "0101"; break;
352 | case "6" : binary = "0110"; break;
353 | case "7" : binary = "0111"; break;
354 | case "8" : binary = "1000"; break;
355 | case "9" : binary = "1001"; break;
356 | case "A" : binary = "1010"; break;
357 | case "B" : binary = "1011"; break;
358 | case "C" : binary = "1100"; break;
359 | case "D" : binary = "1101"; break;
360 | case "E" : binary = "1110"; break;
361 | case "F" : binary = "1111"; break;
362 | }
363 | return binary;
364 | }
365 |
366 | /*
367 | * chang the bit(it's length = 64) into the string
368 | *
369 | * return string
370 | */
371 | function byteToString(byteData){
372 | var str="";
373 | for(i = 0;i<4;i++){
374 | var count=0;
375 | for(j=0;j<16;j++){
376 | var pow=1;
377 | for(m=15;m>j;m--){
378 | pow*=2;
379 | }
380 | count+=byteData[16*i+j]*pow;
381 | }
382 | if(count != 0){
383 | str+=String.fromCharCode(count);
384 | }
385 | }
386 | return str;
387 | }
388 |
389 | function bt64ToHex(byteData){
390 | var hex = "";
391 | for(i = 0;i<16;i++){
392 | var bt = "";
393 | for(j=0;j<4;j++){
394 | bt += byteData[i*4+j];
395 | }
396 | hex+=bt4ToHex(bt);
397 | }
398 | return hex;
399 | }
400 |
401 | function hexToBt64(hex){
402 | var binary = "";
403 | for(i = 0;i<16;i++){
404 | binary+=hexToBt4(hex.substring(i,i+1));
405 | }
406 | return binary;
407 | }
408 |
409 | /*
410 | * the 64 bit des core arithmetic
411 | */
412 |
413 | function enc(dataByte,keyByte){
414 | var keys = generateKeys(keyByte);
415 | var ipByte = initPermute(dataByte);
416 | var ipLeft = new Array(32);
417 | var ipRight = new Array(32);
418 | var tempLeft = new Array(32);
419 | var i = 0,j = 0,k = 0,m = 0, n = 0;
420 | for(k = 0;k < 32;k ++){
421 | ipLeft[k] = ipByte[k];
422 | ipRight[k] = ipByte[32+k];
423 | }
424 | for(i = 0;i < 16;i ++){
425 | for(j = 0;j < 32;j ++){
426 | tempLeft[j] = ipLeft[j];
427 | ipLeft[j] = ipRight[j];
428 | }
429 | var key = new Array(48);
430 | for(m = 0;m < 48;m ++){
431 | key[m] = keys[i][m];
432 | }
433 | var tempRight = xor(pPermute(sBoxPermute(xor(expandPermute(ipRight),key))), tempLeft);
434 | for(n = 0;n < 32;n ++){
435 | ipRight[n] = tempRight[n];
436 | }
437 |
438 | }
439 |
440 |
441 | var finalData =new Array(64);
442 | for(i = 0;i < 32;i ++){
443 | finalData[i] = ipRight[i];
444 | finalData[32+i] = ipLeft[i];
445 | }
446 | return finallyPermute(finalData);
447 | }
448 |
449 | function dec(dataByte,keyByte){
450 | var keys = generateKeys(keyByte);
451 | var ipByte = initPermute(dataByte);
452 | var ipLeft = new Array(32);
453 | var ipRight = new Array(32);
454 | var tempLeft = new Array(32);
455 | var i = 0,j = 0,k = 0,m = 0, n = 0;
456 | for(k = 0;k < 32;k ++){
457 | ipLeft[k] = ipByte[k];
458 | ipRight[k] = ipByte[32+k];
459 | }
460 | for(i = 15;i >= 0;i --){
461 | for(j = 0;j < 32;j ++){
462 | tempLeft[j] = ipLeft[j];
463 | ipLeft[j] = ipRight[j];
464 | }
465 | var key = new Array(48);
466 | for(m = 0;m < 48;m ++){
467 | key[m] = keys[i][m];
468 | }
469 |
470 | var tempRight = xor(pPermute(sBoxPermute(xor(expandPermute(ipRight),key))), tempLeft);
471 | for(n = 0;n < 32;n ++){
472 | ipRight[n] = tempRight[n];
473 | }
474 | }
475 |
476 |
477 | var finalData =new Array(64);
478 | for(i = 0;i < 32;i ++){
479 | finalData[i] = ipRight[i];
480 | finalData[32+i] = ipLeft[i];
481 | }
482 | return finallyPermute(finalData);
483 | }
484 |
485 | function initPermute(originalData){
486 | var ipByte = new Array(64);
487 | for (i = 0, m = 1, n = 0; i < 4; i++, m += 2, n += 2) {
488 | for (j = 7, k = 0; j >= 0; j--, k++) {
489 | ipByte[i * 8 + k] = originalData[j * 8 + m];
490 | ipByte[i * 8 + k + 32] = originalData[j * 8 + n];
491 | }
492 | }
493 | return ipByte;
494 | }
495 |
496 | function expandPermute(rightData){
497 | var epByte = new Array(48);
498 | for (i = 0; i < 8; i++) {
499 | if (i == 0) {
500 | epByte[i * 6 + 0] = rightData[31];
501 | } else {
502 | epByte[i * 6 + 0] = rightData[i * 4 - 1];
503 | }
504 | epByte[i * 6 + 1] = rightData[i * 4 + 0];
505 | epByte[i * 6 + 2] = rightData[i * 4 + 1];
506 | epByte[i * 6 + 3] = rightData[i * 4 + 2];
507 | epByte[i * 6 + 4] = rightData[i * 4 + 3];
508 | if (i == 7) {
509 | epByte[i * 6 + 5] = rightData[0];
510 | } else {
511 | epByte[i * 6 + 5] = rightData[i * 4 + 4];
512 | }
513 | }
514 | return epByte;
515 | }
516 |
517 | function xor(byteOne,byteTwo){
518 | var xorByte = new Array(byteOne.length);
519 | for(i = 0;i < byteOne.length; i ++){
520 | xorByte[i] = byteOne[i] ^ byteTwo[i];
521 | }
522 | return xorByte;
523 | }
524 |
525 | function sBoxPermute(expandByte){
526 |
527 | var sBoxByte = new Array(32);
528 | var binary = "";
529 | var s1 = [
530 | [14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7],
531 | [0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8],
532 | [4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0],
533 | [15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13 ]];
534 |
535 | /* Table - s2 */
536 | var s2 = [
537 | [15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10],
538 | [3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5],
539 | [0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15],
540 | [13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9 ]];
541 |
542 | /* Table - s3 */
543 | var s3= [
544 | [10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8],
545 | [13, 7, 0, 9, 3, 4, 6, 10, 2, 8, 5, 14, 12, 11, 15, 1],
546 | [13, 6, 4, 9, 8, 15, 3, 0, 11, 1, 2, 12, 5, 10, 14, 7],
547 | [1, 10, 13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12 ]];
548 | /* Table - s4 */
549 | var s4 = [
550 | [7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15],
551 | [13, 8, 11, 5, 6, 15, 0, 3, 4, 7, 2, 12, 1, 10, 14, 9],
552 | [10, 6, 9, 0, 12, 11, 7, 13, 15, 1, 3, 14, 5, 2, 8, 4],
553 | [3, 15, 0, 6, 10, 1, 13, 8, 9, 4, 5, 11, 12, 7, 2, 14 ]];
554 |
555 | /* Table - s5 */
556 | var s5 = [
557 | [2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9],
558 | [14, 11, 2, 12, 4, 7, 13, 1, 5, 0, 15, 10, 3, 9, 8, 6],
559 | [4, 2, 1, 11, 10, 13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14],
560 | [11, 8, 12, 7, 1, 14, 2, 13, 6, 15, 0, 9, 10, 4, 5, 3 ]];
561 |
562 | /* Table - s6 */
563 | var s6 = [
564 | [12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11],
565 | [10, 15, 4, 2, 7, 12, 9, 5, 6, 1, 13, 14, 0, 11, 3, 8],
566 | [9, 14, 15, 5, 2, 8, 12, 3, 7, 0, 4, 10, 1, 13, 11, 6],
567 | [4, 3, 2, 12, 9, 5, 15, 10, 11, 14, 1, 7, 6, 0, 8, 13 ]];
568 |
569 | /* Table - s7 */
570 | var s7 = [
571 | [4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1],
572 | [13, 0, 11, 7, 4, 9, 1, 10, 14, 3, 5, 12, 2, 15, 8, 6],
573 | [1, 4, 11, 13, 12, 3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2],
574 | [6, 11, 13, 8, 1, 4, 10, 7, 9, 5, 0, 15, 14, 2, 3, 12]];
575 |
576 | /* Table - s8 */
577 | var s8 = [
578 | [13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7],
579 | [1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2],
580 | [7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8],
581 | [2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11]];
582 |
583 | for(m=0;m<8;m++){
584 | var i=0,j=0;
585 | i = expandByte[m*6+0]*2+expandByte[m*6+5];
586 | j = expandByte[m * 6 + 1] * 2 * 2 * 2
587 | + expandByte[m * 6 + 2] * 2* 2
588 | + expandByte[m * 6 + 3] * 2
589 | + expandByte[m * 6 + 4];
590 | switch (m) {
591 | case 0 :
592 | binary = getBoxBinary(s1[i][j]);
593 | break;
594 | case 1 :
595 | binary = getBoxBinary(s2[i][j]);
596 | break;
597 | case 2 :
598 | binary = getBoxBinary(s3[i][j]);
599 | break;
600 | case 3 :
601 | binary = getBoxBinary(s4[i][j]);
602 | break;
603 | case 4 :
604 | binary = getBoxBinary(s5[i][j]);
605 | break;
606 | case 5 :
607 | binary = getBoxBinary(s6[i][j]);
608 | break;
609 | case 6 :
610 | binary = getBoxBinary(s7[i][j]);
611 | break;
612 | case 7 :
613 | binary = getBoxBinary(s8[i][j]);
614 | break;
615 | }
616 | sBoxByte[m*4+0] = parseInt(binary.substring(0,1));
617 | sBoxByte[m*4+1] = parseInt(binary.substring(1,2));
618 | sBoxByte[m*4+2] = parseInt(binary.substring(2,3));
619 | sBoxByte[m*4+3] = parseInt(binary.substring(3,4));
620 | }
621 | return sBoxByte;
622 | }
623 |
624 | function pPermute(sBoxByte){
625 | var pBoxPermute = new Array(32);
626 | pBoxPermute[ 0] = sBoxByte[15];
627 | pBoxPermute[ 1] = sBoxByte[ 6];
628 | pBoxPermute[ 2] = sBoxByte[19];
629 | pBoxPermute[ 3] = sBoxByte[20];
630 | pBoxPermute[ 4] = sBoxByte[28];
631 | pBoxPermute[ 5] = sBoxByte[11];
632 | pBoxPermute[ 6] = sBoxByte[27];
633 | pBoxPermute[ 7] = sBoxByte[16];
634 | pBoxPermute[ 8] = sBoxByte[ 0];
635 | pBoxPermute[ 9] = sBoxByte[14];
636 | pBoxPermute[10] = sBoxByte[22];
637 | pBoxPermute[11] = sBoxByte[25];
638 | pBoxPermute[12] = sBoxByte[ 4];
639 | pBoxPermute[13] = sBoxByte[17];
640 | pBoxPermute[14] = sBoxByte[30];
641 | pBoxPermute[15] = sBoxByte[ 9];
642 | pBoxPermute[16] = sBoxByte[ 1];
643 | pBoxPermute[17] = sBoxByte[ 7];
644 | pBoxPermute[18] = sBoxByte[23];
645 | pBoxPermute[19] = sBoxByte[13];
646 | pBoxPermute[20] = sBoxByte[31];
647 | pBoxPermute[21] = sBoxByte[26];
648 | pBoxPermute[22] = sBoxByte[ 2];
649 | pBoxPermute[23] = sBoxByte[ 8];
650 | pBoxPermute[24] = sBoxByte[18];
651 | pBoxPermute[25] = sBoxByte[12];
652 | pBoxPermute[26] = sBoxByte[29];
653 | pBoxPermute[27] = sBoxByte[ 5];
654 | pBoxPermute[28] = sBoxByte[21];
655 | pBoxPermute[29] = sBoxByte[10];
656 | pBoxPermute[30] = sBoxByte[ 3];
657 | pBoxPermute[31] = sBoxByte[24];
658 | return pBoxPermute;
659 | }
660 |
661 | function finallyPermute(endByte){
662 | var fpByte = new Array(64);
663 | fpByte[ 0] = endByte[39];
664 | fpByte[ 1] = endByte[ 7];
665 | fpByte[ 2] = endByte[47];
666 | fpByte[ 3] = endByte[15];
667 | fpByte[ 4] = endByte[55];
668 | fpByte[ 5] = endByte[23];
669 | fpByte[ 6] = endByte[63];
670 | fpByte[ 7] = endByte[31];
671 | fpByte[ 8] = endByte[38];
672 | fpByte[ 9] = endByte[ 6];
673 | fpByte[10] = endByte[46];
674 | fpByte[11] = endByte[14];
675 | fpByte[12] = endByte[54];
676 | fpByte[13] = endByte[22];
677 | fpByte[14] = endByte[62];
678 | fpByte[15] = endByte[30];
679 | fpByte[16] = endByte[37];
680 | fpByte[17] = endByte[ 5];
681 | fpByte[18] = endByte[45];
682 | fpByte[19] = endByte[13];
683 | fpByte[20] = endByte[53];
684 | fpByte[21] = endByte[21];
685 | fpByte[22] = endByte[61];
686 | fpByte[23] = endByte[29];
687 | fpByte[24] = endByte[36];
688 | fpByte[25] = endByte[ 4];
689 | fpByte[26] = endByte[44];
690 | fpByte[27] = endByte[12];
691 | fpByte[28] = endByte[52];
692 | fpByte[29] = endByte[20];
693 | fpByte[30] = endByte[60];
694 | fpByte[31] = endByte[28];
695 | fpByte[32] = endByte[35];
696 | fpByte[33] = endByte[ 3];
697 | fpByte[34] = endByte[43];
698 | fpByte[35] = endByte[11];
699 | fpByte[36] = endByte[51];
700 | fpByte[37] = endByte[19];
701 | fpByte[38] = endByte[59];
702 | fpByte[39] = endByte[27];
703 | fpByte[40] = endByte[34];
704 | fpByte[41] = endByte[ 2];
705 | fpByte[42] = endByte[42];
706 | fpByte[43] = endByte[10];
707 | fpByte[44] = endByte[50];
708 | fpByte[45] = endByte[18];
709 | fpByte[46] = endByte[58];
710 | fpByte[47] = endByte[26];
711 | fpByte[48] = endByte[33];
712 | fpByte[49] = endByte[ 1];
713 | fpByte[50] = endByte[41];
714 | fpByte[51] = endByte[ 9];
715 | fpByte[52] = endByte[49];
716 | fpByte[53] = endByte[17];
717 | fpByte[54] = endByte[57];
718 | fpByte[55] = endByte[25];
719 | fpByte[56] = endByte[32];
720 | fpByte[57] = endByte[ 0];
721 | fpByte[58] = endByte[40];
722 | fpByte[59] = endByte[ 8];
723 | fpByte[60] = endByte[48];
724 | fpByte[61] = endByte[16];
725 | fpByte[62] = endByte[56];
726 | fpByte[63] = endByte[24];
727 | return fpByte;
728 | }
729 |
730 | function getBoxBinary(i) {
731 | var binary = "";
732 | switch (i) {
733 | case 0 :binary = "0000";break;
734 | case 1 :binary = "0001";break;
735 | case 2 :binary = "0010";break;
736 | case 3 :binary = "0011";break;
737 | case 4 :binary = "0100";break;
738 | case 5 :binary = "0101";break;
739 | case 6 :binary = "0110";break;
740 | case 7 :binary = "0111";break;
741 | case 8 :binary = "1000";break;
742 | case 9 :binary = "1001";break;
743 | case 10 :binary = "1010";break;
744 | case 11 :binary = "1011";break;
745 | case 12 :binary = "1100";break;
746 | case 13 :binary = "1101";break;
747 | case 14 :binary = "1110";break;
748 | case 15 :binary = "1111";break;
749 | }
750 | return binary;
751 | }
752 | /*
753 | * generate 16 keys for xor
754 | *
755 | */
756 | function generateKeys(keyByte){
757 | var key = new Array(56);
758 | var keys = new Array();
759 |
760 | keys[ 0] = new Array();
761 | keys[ 1] = new Array();
762 | keys[ 2] = new Array();
763 | keys[ 3] = new Array();
764 | keys[ 4] = new Array();
765 | keys[ 5] = new Array();
766 | keys[ 6] = new Array();
767 | keys[ 7] = new Array();
768 | keys[ 8] = new Array();
769 | keys[ 9] = new Array();
770 | keys[10] = new Array();
771 | keys[11] = new Array();
772 | keys[12] = new Array();
773 | keys[13] = new Array();
774 | keys[14] = new Array();
775 | keys[15] = new Array();
776 | var loop = [1,1,2,2,2,2,2,2,1,2,2,2,2,2,2,1];
777 |
778 | for(i=0;i<7;i++){
779 | for(j=0,k=7;j<8;j++,k--){
780 | key[i*8+j]=keyByte[8*k+i];
781 | }
782 | }
783 |
784 | var i = 0;
785 | for(i = 0;i < 16;i ++){
786 | var tempLeft=0;
787 | var tempRight=0;
788 | for(j = 0; j < loop[i];j ++){
789 | tempLeft = key[0];
790 | tempRight = key[28];
791 | for(k = 0;k < 27 ;k ++){
792 | key[k] = key[k+1];
793 | key[28+k] = key[29+k];
794 | }
795 | key[27]=tempLeft;
796 | key[55]=tempRight;
797 | }
798 | var tempKey = new Array(48);
799 | tempKey[ 0] = key[13];
800 | tempKey[ 1] = key[16];
801 | tempKey[ 2] = key[10];
802 | tempKey[ 3] = key[23];
803 | tempKey[ 4] = key[ 0];
804 | tempKey[ 5] = key[ 4];
805 | tempKey[ 6] = key[ 2];
806 | tempKey[ 7] = key[27];
807 | tempKey[ 8] = key[14];
808 | tempKey[ 9] = key[ 5];
809 | tempKey[10] = key[20];
810 | tempKey[11] = key[ 9];
811 | tempKey[12] = key[22];
812 | tempKey[13] = key[18];
813 | tempKey[14] = key[11];
814 | tempKey[15] = key[ 3];
815 | tempKey[16] = key[25];
816 | tempKey[17] = key[ 7];
817 | tempKey[18] = key[15];
818 | tempKey[19] = key[ 6];
819 | tempKey[20] = key[26];
820 | tempKey[21] = key[19];
821 | tempKey[22] = key[12];
822 | tempKey[23] = key[ 1];
823 | tempKey[24] = key[40];
824 | tempKey[25] = key[51];
825 | tempKey[26] = key[30];
826 | tempKey[27] = key[36];
827 | tempKey[28] = key[46];
828 | tempKey[29] = key[54];
829 | tempKey[30] = key[29];
830 | tempKey[31] = key[39];
831 | tempKey[32] = key[50];
832 | tempKey[33] = key[44];
833 | tempKey[34] = key[32];
834 | tempKey[35] = key[47];
835 | tempKey[36] = key[43];
836 | tempKey[37] = key[48];
837 | tempKey[38] = key[38];
838 | tempKey[39] = key[55];
839 | tempKey[40] = key[33];
840 | tempKey[41] = key[52];
841 | tempKey[42] = key[45];
842 | tempKey[43] = key[41];
843 | tempKey[44] = key[49];
844 | tempKey[45] = key[35];
845 | tempKey[46] = key[28];
846 | tempKey[47] = key[31];
847 | switch(i){
848 | case 0: for(m=0;m < 48 ;m++){ keys[ 0][m] = tempKey[m]; } break;
849 | case 1: for(m=0;m < 48 ;m++){ keys[ 1][m] = tempKey[m]; } break;
850 | case 2: for(m=0;m < 48 ;m++){ keys[ 2][m] = tempKey[m]; } break;
851 | case 3: for(m=0;m < 48 ;m++){ keys[ 3][m] = tempKey[m]; } break;
852 | case 4: for(m=0;m < 48 ;m++){ keys[ 4][m] = tempKey[m]; } break;
853 | case 5: for(m=0;m < 48 ;m++){ keys[ 5][m] = tempKey[m]; } break;
854 | case 6: for(m=0;m < 48 ;m++){ keys[ 6][m] = tempKey[m]; } break;
855 | case 7: for(m=0;m < 48 ;m++){ keys[ 7][m] = tempKey[m]; } break;
856 | case 8: for(m=0;m < 48 ;m++){ keys[ 8][m] = tempKey[m]; } break;
857 | case 9: for(m=0;m < 48 ;m++){ keys[ 9][m] = tempKey[m]; } break;
858 | case 10: for(m=0;m < 48 ;m++){ keys[10][m] = tempKey[m]; } break;
859 | case 11: for(m=0;m < 48 ;m++){ keys[11][m] = tempKey[m]; } break;
860 | case 12: for(m=0;m < 48 ;m++){ keys[12][m] = tempKey[m]; } break;
861 | case 13: for(m=0;m < 48 ;m++){ keys[13][m] = tempKey[m]; } break;
862 | case 14: for(m=0;m < 48 ;m++){ keys[14][m] = tempKey[m]; } break;
863 | case 15: for(m=0;m < 48 ;m++){ keys[15][m] = tempKey[m]; } break;
864 | }
865 | }
866 | return keys;
867 | }
--------------------------------------------------------------------------------
/教务系统查询课表例子/des.js:
--------------------------------------------------------------------------------
1 | /**
2 | * DES加密解密
3 | * @Copyright Copyright (c) 2006
4 | * @author Guapo
5 | * @see DESCore
6 | */
7 |
8 | /*
9 | * encrypt the string to string made up of hex
10 | * return the encrypted string
11 | */
12 | function strEnc(data,firstKey,secondKey,thirdKey){
13 |
14 | var leng = data.length;
15 | var encData = "";
16 | var firstKeyBt,secondKeyBt,thirdKeyBt,firstLength,secondLength,thirdLength;
17 | if(firstKey != null && firstKey != ""){
18 | firstKeyBt = getKeyBytes(firstKey);
19 | firstLength = firstKeyBt.length;
20 | }
21 | if(secondKey != null && secondKey != ""){
22 | secondKeyBt = getKeyBytes(secondKey);
23 | secondLength = secondKeyBt.length;
24 | }
25 | if(thirdKey != null && thirdKey != ""){
26 | thirdKeyBt = getKeyBytes(thirdKey);
27 | thirdLength = thirdKeyBt.length;
28 | }
29 |
30 | if(leng > 0){
31 | if(leng < 4){
32 | var bt = strToBt(data);
33 | var encByte ;
34 | if(firstKey != null && firstKey !="" && secondKey != null && secondKey != "" && thirdKey != null && thirdKey != ""){
35 | var tempBt;
36 | var x,y,z;
37 | tempBt = bt;
38 | for(x = 0;x < firstLength ;x ++){
39 | tempBt = enc(tempBt,firstKeyBt[x]);
40 | }
41 | for(y = 0;y < secondLength ;y ++){
42 | tempBt = enc(tempBt,secondKeyBt[y]);
43 | }
44 | for(z = 0;z < thirdLength ;z ++){
45 | tempBt = enc(tempBt,thirdKeyBt[z]);
46 | }
47 | encByte = tempBt;
48 | }else{
49 | if(firstKey != null && firstKey !="" && secondKey != null && secondKey != ""){
50 | var tempBt;
51 | var x,y;
52 | tempBt = bt;
53 | for(x = 0;x < firstLength ;x ++){
54 | tempBt = enc(tempBt,firstKeyBt[x]);
55 | }
56 | for(y = 0;y < secondLength ;y ++){
57 | tempBt = enc(tempBt,secondKeyBt[y]);
58 | }
59 | encByte = tempBt;
60 | }else{
61 | if(firstKey != null && firstKey !=""){
62 | var tempBt;
63 | var x = 0;
64 | tempBt = bt;
65 | for(x = 0;x < firstLength ;x ++){
66 | tempBt = enc(tempBt,firstKeyBt[x]);
67 | }
68 | encByte = tempBt;
69 | }
70 | }
71 | }
72 | encData = bt64ToHex(encByte);
73 | }else{
74 | var iterator = parseInt(leng/4);
75 | var remainder = leng%4;
76 | var i=0;
77 | for(i = 0;i < iterator;i++){
78 | var tempData = data.substring(i*4+0,i*4+4);
79 | var tempByte = strToBt(tempData);
80 | var encByte ;
81 | if(firstKey != null && firstKey !="" && secondKey != null && secondKey != "" && thirdKey != null && thirdKey != ""){
82 | var tempBt;
83 | var x,y,z;
84 | tempBt = tempByte;
85 | for(x = 0;x < firstLength ;x ++){
86 | tempBt = enc(tempBt,firstKeyBt[x]);
87 | }
88 | for(y = 0;y < secondLength ;y ++){
89 | tempBt = enc(tempBt,secondKeyBt[y]);
90 | }
91 | for(z = 0;z < thirdLength ;z ++){
92 | tempBt = enc(tempBt,thirdKeyBt[z]);
93 | }
94 | encByte = tempBt;
95 | }else{
96 | if(firstKey != null && firstKey !="" && secondKey != null && secondKey != ""){
97 | var tempBt;
98 | var x,y;
99 | tempBt = tempByte;
100 | for(x = 0;x < firstLength ;x ++){
101 | tempBt = enc(tempBt,firstKeyBt[x]);
102 | }
103 | for(y = 0;y < secondLength ;y ++){
104 | tempBt = enc(tempBt,secondKeyBt[y]);
105 | }
106 | encByte = tempBt;
107 | }else{
108 | if(firstKey != null && firstKey !=""){
109 | var tempBt;
110 | var x;
111 | tempBt = tempByte;
112 | for(x = 0;x < firstLength ;x ++){
113 | tempBt = enc(tempBt,firstKeyBt[x]);
114 | }
115 | encByte = tempBt;
116 | }
117 | }
118 | }
119 | encData += bt64ToHex(encByte);
120 | }
121 | if(remainder > 0){
122 | var remainderData = data.substring(iterator*4+0,leng);
123 | var tempByte = strToBt(remainderData);
124 | var encByte ;
125 | if(firstKey != null && firstKey !="" && secondKey != null && secondKey != "" && thirdKey != null && thirdKey != ""){
126 | var tempBt;
127 | var x,y,z;
128 | tempBt = tempByte;
129 | for(x = 0;x < firstLength ;x ++){
130 | tempBt = enc(tempBt,firstKeyBt[x]);
131 | }
132 | for(y = 0;y < secondLength ;y ++){
133 | tempBt = enc(tempBt,secondKeyBt[y]);
134 | }
135 | for(z = 0;z < thirdLength ;z ++){
136 | tempBt = enc(tempBt,thirdKeyBt[z]);
137 | }
138 | encByte = tempBt;
139 | }else{
140 | if(firstKey != null && firstKey !="" && secondKey != null && secondKey != ""){
141 | var tempBt;
142 | var x,y;
143 | tempBt = tempByte;
144 | for(x = 0;x < firstLength ;x ++){
145 | tempBt = enc(tempBt,firstKeyBt[x]);
146 | }
147 | for(y = 0;y < secondLength ;y ++){
148 | tempBt = enc(tempBt,secondKeyBt[y]);
149 | }
150 | encByte = tempBt;
151 | }else{
152 | if(firstKey != null && firstKey !=""){
153 | var tempBt;
154 | var x;
155 | tempBt = tempByte;
156 | for(x = 0;x < firstLength ;x ++){
157 | tempBt = enc(tempBt,firstKeyBt[x]);
158 | }
159 | encByte = tempBt;
160 | }
161 | }
162 | }
163 | encData += bt64ToHex(encByte);
164 | }
165 | }
166 | }
167 | return encData;
168 | }
169 |
170 | /*
171 | * decrypt the encrypted string to the original string
172 | *
173 | * return the original string
174 | */
175 | function strDec(data,firstKey,secondKey,thirdKey){
176 | var leng = data.length;
177 | var decStr = "";
178 | var firstKeyBt,secondKeyBt,thirdKeyBt,firstLength,secondLength,thirdLength;
179 | if(firstKey != null && firstKey != ""){
180 | firstKeyBt = getKeyBytes(firstKey);
181 | firstLength = firstKeyBt.length;
182 | }
183 | if(secondKey != null && secondKey != ""){
184 | secondKeyBt = getKeyBytes(secondKey);
185 | secondLength = secondKeyBt.length;
186 | }
187 | if(thirdKey != null && thirdKey != ""){
188 | thirdKeyBt = getKeyBytes(thirdKey);
189 | thirdLength = thirdKeyBt.length;
190 | }
191 |
192 | var iterator = parseInt(leng/16);
193 | var i=0;
194 | for(i = 0;i < iterator;i++){
195 | var tempData = data.substring(i*16+0,i*16+16);
196 | var strByte = hexToBt64(tempData);
197 | var intByte = new Array(64);
198 | var j = 0;
199 | for(j = 0;j < 64; j++){
200 | intByte[j] = parseInt(strByte.substring(j,j+1));
201 | }
202 | var decByte;
203 | if(firstKey != null && firstKey !="" && secondKey != null && secondKey != "" && thirdKey != null && thirdKey != ""){
204 | var tempBt;
205 | var x,y,z;
206 | tempBt = intByte;
207 | for(x = thirdLength - 1;x >= 0;x --){
208 | tempBt = dec(tempBt,thirdKeyBt[x]);
209 | }
210 | for(y = secondLength - 1;y >= 0;y --){
211 | tempBt = dec(tempBt,secondKeyBt[y]);
212 | }
213 | for(z = firstLength - 1;z >= 0 ;z --){
214 | tempBt = dec(tempBt,firstKeyBt[z]);
215 | }
216 | decByte = tempBt;
217 | }else{
218 | if(firstKey != null && firstKey !="" && secondKey != null && secondKey != ""){
219 | var tempBt;
220 | var x,y,z;
221 | tempBt = intByte;
222 | for(x = secondLength - 1;x >= 0 ;x --){
223 | tempBt = dec(tempBt,secondKeyBt[x]);
224 | }
225 | for(y = firstLength - 1;y >= 0 ;y --){
226 | tempBt = dec(tempBt,firstKeyBt[y]);
227 | }
228 | decByte = tempBt;
229 | }else{
230 | if(firstKey != null && firstKey !=""){
231 | var tempBt;
232 | var x,y,z;
233 | tempBt = intByte;
234 | for(x = firstLength - 1;x >= 0 ;x --){
235 | tempBt = dec(tempBt,firstKeyBt[x]);
236 | }
237 | decByte = tempBt;
238 | }
239 | }
240 | }
241 | decStr += byteToString(decByte);
242 | }
243 | return decStr;
244 | }
245 | /*
246 | * chang the string into the bit array
247 | *
248 | * return bit array(it's length % 64 = 0)
249 | */
250 | function getKeyBytes(key){
251 | var keyBytes = new Array();
252 | var leng = key.length;
253 | var iterator = parseInt(leng/4);
254 | var remainder = leng%4;
255 | var i = 0;
256 | for(i = 0;i < iterator; i ++){
257 | keyBytes[i] = strToBt(key.substring(i*4+0,i*4+4));
258 | }
259 | if(remainder > 0){
260 | keyBytes[i] = strToBt(key.substring(i*4+0,leng));
261 | }
262 | return keyBytes;
263 | }
264 |
265 | /*
266 | * chang the string(it's length <= 4) into the bit array
267 | *
268 | * return bit array(it's length = 64)
269 | */
270 | function strToBt(str){
271 | var leng = str.length;
272 | var bt = new Array(64);
273 | if(leng < 4){
274 | var i=0,j=0,p=0,q=0;
275 | for(i = 0;ij;m--){
280 | pow *= 2;
281 | }
282 | bt[16*i+j]=parseInt(k/pow)%2;
283 | }
284 | }
285 | for(p = leng;p<4;p++){
286 | var k = 0;
287 | for(q=0;q<16;q++){
288 | var pow=1,m=0;
289 | for(m=15;m>q;m--){
290 | pow *= 2;
291 | }
292 | bt[16*p+q]=parseInt(k/pow)%2;
293 | }
294 | }
295 | }else{
296 | for(i = 0;i<4;i++){
297 | var k = str.charCodeAt(i);
298 | for(j=0;j<16;j++){
299 | var pow=1;
300 | for(m=15;m>j;m--){
301 | pow *= 2;
302 | }
303 | bt[16*i+j]=parseInt(k/pow)%2;
304 | }
305 | }
306 | }
307 | return bt;
308 | }
309 |
310 | /*
311 | * chang the bit(it's length = 4) into the hex
312 | *
313 | * return hex
314 | */
315 | function bt4ToHex(binary) {
316 | var hex;
317 | switch (binary) {
318 | case "0000" : hex = "0"; break;
319 | case "0001" : hex = "1"; break;
320 | case "0010" : hex = "2"; break;
321 | case "0011" : hex = "3"; break;
322 | case "0100" : hex = "4"; break;
323 | case "0101" : hex = "5"; break;
324 | case "0110" : hex = "6"; break;
325 | case "0111" : hex = "7"; break;
326 | case "1000" : hex = "8"; break;
327 | case "1001" : hex = "9"; break;
328 | case "1010" : hex = "A"; break;
329 | case "1011" : hex = "B"; break;
330 | case "1100" : hex = "C"; break;
331 | case "1101" : hex = "D"; break;
332 | case "1110" : hex = "E"; break;
333 | case "1111" : hex = "F"; break;
334 | }
335 | return hex;
336 | }
337 |
338 | /*
339 | * chang the hex into the bit(it's length = 4)
340 | *
341 | * return the bit(it's length = 4)
342 | */
343 | function hexToBt4(hex) {
344 | var binary;
345 | switch (hex) {
346 | case "0" : binary = "0000"; break;
347 | case "1" : binary = "0001"; break;
348 | case "2" : binary = "0010"; break;
349 | case "3" : binary = "0011"; break;
350 | case "4" : binary = "0100"; break;
351 | case "5" : binary = "0101"; break;
352 | case "6" : binary = "0110"; break;
353 | case "7" : binary = "0111"; break;
354 | case "8" : binary = "1000"; break;
355 | case "9" : binary = "1001"; break;
356 | case "A" : binary = "1010"; break;
357 | case "B" : binary = "1011"; break;
358 | case "C" : binary = "1100"; break;
359 | case "D" : binary = "1101"; break;
360 | case "E" : binary = "1110"; break;
361 | case "F" : binary = "1111"; break;
362 | }
363 | return binary;
364 | }
365 |
366 | /*
367 | * chang the bit(it's length = 64) into the string
368 | *
369 | * return string
370 | */
371 | function byteToString(byteData){
372 | var str="";
373 | for(i = 0;i<4;i++){
374 | var count=0;
375 | for(j=0;j<16;j++){
376 | var pow=1;
377 | for(m=15;m>j;m--){
378 | pow*=2;
379 | }
380 | count+=byteData[16*i+j]*pow;
381 | }
382 | if(count != 0){
383 | str+=String.fromCharCode(count);
384 | }
385 | }
386 | return str;
387 | }
388 |
389 | function bt64ToHex(byteData){
390 | var hex = "";
391 | for(i = 0;i<16;i++){
392 | var bt = "";
393 | for(j=0;j<4;j++){
394 | bt += byteData[i*4+j];
395 | }
396 | hex+=bt4ToHex(bt);
397 | }
398 | return hex;
399 | }
400 |
401 | function hexToBt64(hex){
402 | var binary = "";
403 | for(i = 0;i<16;i++){
404 | binary+=hexToBt4(hex.substring(i,i+1));
405 | }
406 | return binary;
407 | }
408 |
409 | /*
410 | * the 64 bit des core arithmetic
411 | */
412 |
413 | function enc(dataByte,keyByte){
414 | var keys = generateKeys(keyByte);
415 | var ipByte = initPermute(dataByte);
416 | var ipLeft = new Array(32);
417 | var ipRight = new Array(32);
418 | var tempLeft = new Array(32);
419 | var i = 0,j = 0,k = 0,m = 0, n = 0;
420 | for(k = 0;k < 32;k ++){
421 | ipLeft[k] = ipByte[k];
422 | ipRight[k] = ipByte[32+k];
423 | }
424 | for(i = 0;i < 16;i ++){
425 | for(j = 0;j < 32;j ++){
426 | tempLeft[j] = ipLeft[j];
427 | ipLeft[j] = ipRight[j];
428 | }
429 | var key = new Array(48);
430 | for(m = 0;m < 48;m ++){
431 | key[m] = keys[i][m];
432 | }
433 | var tempRight = xor(pPermute(sBoxPermute(xor(expandPermute(ipRight),key))), tempLeft);
434 | for(n = 0;n < 32;n ++){
435 | ipRight[n] = tempRight[n];
436 | }
437 |
438 | }
439 |
440 |
441 | var finalData =new Array(64);
442 | for(i = 0;i < 32;i ++){
443 | finalData[i] = ipRight[i];
444 | finalData[32+i] = ipLeft[i];
445 | }
446 | return finallyPermute(finalData);
447 | }
448 |
449 | function dec(dataByte,keyByte){
450 | var keys = generateKeys(keyByte);
451 | var ipByte = initPermute(dataByte);
452 | var ipLeft = new Array(32);
453 | var ipRight = new Array(32);
454 | var tempLeft = new Array(32);
455 | var i = 0,j = 0,k = 0,m = 0, n = 0;
456 | for(k = 0;k < 32;k ++){
457 | ipLeft[k] = ipByte[k];
458 | ipRight[k] = ipByte[32+k];
459 | }
460 | for(i = 15;i >= 0;i --){
461 | for(j = 0;j < 32;j ++){
462 | tempLeft[j] = ipLeft[j];
463 | ipLeft[j] = ipRight[j];
464 | }
465 | var key = new Array(48);
466 | for(m = 0;m < 48;m ++){
467 | key[m] = keys[i][m];
468 | }
469 |
470 | var tempRight = xor(pPermute(sBoxPermute(xor(expandPermute(ipRight),key))), tempLeft);
471 | for(n = 0;n < 32;n ++){
472 | ipRight[n] = tempRight[n];
473 | }
474 | }
475 |
476 |
477 | var finalData =new Array(64);
478 | for(i = 0;i < 32;i ++){
479 | finalData[i] = ipRight[i];
480 | finalData[32+i] = ipLeft[i];
481 | }
482 | return finallyPermute(finalData);
483 | }
484 |
485 | function initPermute(originalData){
486 | var ipByte = new Array(64);
487 | for (i = 0, m = 1, n = 0; i < 4; i++, m += 2, n += 2) {
488 | for (j = 7, k = 0; j >= 0; j--, k++) {
489 | ipByte[i * 8 + k] = originalData[j * 8 + m];
490 | ipByte[i * 8 + k + 32] = originalData[j * 8 + n];
491 | }
492 | }
493 | return ipByte;
494 | }
495 |
496 | function expandPermute(rightData){
497 | var epByte = new Array(48);
498 | for (i = 0; i < 8; i++) {
499 | if (i == 0) {
500 | epByte[i * 6 + 0] = rightData[31];
501 | } else {
502 | epByte[i * 6 + 0] = rightData[i * 4 - 1];
503 | }
504 | epByte[i * 6 + 1] = rightData[i * 4 + 0];
505 | epByte[i * 6 + 2] = rightData[i * 4 + 1];
506 | epByte[i * 6 + 3] = rightData[i * 4 + 2];
507 | epByte[i * 6 + 4] = rightData[i * 4 + 3];
508 | if (i == 7) {
509 | epByte[i * 6 + 5] = rightData[0];
510 | } else {
511 | epByte[i * 6 + 5] = rightData[i * 4 + 4];
512 | }
513 | }
514 | return epByte;
515 | }
516 |
517 | function xor(byteOne,byteTwo){
518 | var xorByte = new Array(byteOne.length);
519 | for(i = 0;i < byteOne.length; i ++){
520 | xorByte[i] = byteOne[i] ^ byteTwo[i];
521 | }
522 | return xorByte;
523 | }
524 |
525 | function sBoxPermute(expandByte){
526 |
527 | var sBoxByte = new Array(32);
528 | var binary = "";
529 | var s1 = [
530 | [14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7],
531 | [0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8],
532 | [4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0],
533 | [15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13 ]];
534 |
535 | /* Table - s2 */
536 | var s2 = [
537 | [15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10],
538 | [3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5],
539 | [0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15],
540 | [13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9 ]];
541 |
542 | /* Table - s3 */
543 | var s3= [
544 | [10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8],
545 | [13, 7, 0, 9, 3, 4, 6, 10, 2, 8, 5, 14, 12, 11, 15, 1],
546 | [13, 6, 4, 9, 8, 15, 3, 0, 11, 1, 2, 12, 5, 10, 14, 7],
547 | [1, 10, 13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12 ]];
548 | /* Table - s4 */
549 | var s4 = [
550 | [7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15],
551 | [13, 8, 11, 5, 6, 15, 0, 3, 4, 7, 2, 12, 1, 10, 14, 9],
552 | [10, 6, 9, 0, 12, 11, 7, 13, 15, 1, 3, 14, 5, 2, 8, 4],
553 | [3, 15, 0, 6, 10, 1, 13, 8, 9, 4, 5, 11, 12, 7, 2, 14 ]];
554 |
555 | /* Table - s5 */
556 | var s5 = [
557 | [2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9],
558 | [14, 11, 2, 12, 4, 7, 13, 1, 5, 0, 15, 10, 3, 9, 8, 6],
559 | [4, 2, 1, 11, 10, 13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14],
560 | [11, 8, 12, 7, 1, 14, 2, 13, 6, 15, 0, 9, 10, 4, 5, 3 ]];
561 |
562 | /* Table - s6 */
563 | var s6 = [
564 | [12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11],
565 | [10, 15, 4, 2, 7, 12, 9, 5, 6, 1, 13, 14, 0, 11, 3, 8],
566 | [9, 14, 15, 5, 2, 8, 12, 3, 7, 0, 4, 10, 1, 13, 11, 6],
567 | [4, 3, 2, 12, 9, 5, 15, 10, 11, 14, 1, 7, 6, 0, 8, 13 ]];
568 |
569 | /* Table - s7 */
570 | var s7 = [
571 | [4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1],
572 | [13, 0, 11, 7, 4, 9, 1, 10, 14, 3, 5, 12, 2, 15, 8, 6],
573 | [1, 4, 11, 13, 12, 3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2],
574 | [6, 11, 13, 8, 1, 4, 10, 7, 9, 5, 0, 15, 14, 2, 3, 12]];
575 |
576 | /* Table - s8 */
577 | var s8 = [
578 | [13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7],
579 | [1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2],
580 | [7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8],
581 | [2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11]];
582 |
583 | for(m=0;m<8;m++){
584 | var i=0,j=0;
585 | i = expandByte[m*6+0]*2+expandByte[m*6+5];
586 | j = expandByte[m * 6 + 1] * 2 * 2 * 2
587 | + expandByte[m * 6 + 2] * 2* 2
588 | + expandByte[m * 6 + 3] * 2
589 | + expandByte[m * 6 + 4];
590 | switch (m) {
591 | case 0 :
592 | binary = getBoxBinary(s1[i][j]);
593 | break;
594 | case 1 :
595 | binary = getBoxBinary(s2[i][j]);
596 | break;
597 | case 2 :
598 | binary = getBoxBinary(s3[i][j]);
599 | break;
600 | case 3 :
601 | binary = getBoxBinary(s4[i][j]);
602 | break;
603 | case 4 :
604 | binary = getBoxBinary(s5[i][j]);
605 | break;
606 | case 5 :
607 | binary = getBoxBinary(s6[i][j]);
608 | break;
609 | case 6 :
610 | binary = getBoxBinary(s7[i][j]);
611 | break;
612 | case 7 :
613 | binary = getBoxBinary(s8[i][j]);
614 | break;
615 | }
616 | sBoxByte[m*4+0] = parseInt(binary.substring(0,1));
617 | sBoxByte[m*4+1] = parseInt(binary.substring(1,2));
618 | sBoxByte[m*4+2] = parseInt(binary.substring(2,3));
619 | sBoxByte[m*4+3] = parseInt(binary.substring(3,4));
620 | }
621 | return sBoxByte;
622 | }
623 |
624 | function pPermute(sBoxByte){
625 | var pBoxPermute = new Array(32);
626 | pBoxPermute[ 0] = sBoxByte[15];
627 | pBoxPermute[ 1] = sBoxByte[ 6];
628 | pBoxPermute[ 2] = sBoxByte[19];
629 | pBoxPermute[ 3] = sBoxByte[20];
630 | pBoxPermute[ 4] = sBoxByte[28];
631 | pBoxPermute[ 5] = sBoxByte[11];
632 | pBoxPermute[ 6] = sBoxByte[27];
633 | pBoxPermute[ 7] = sBoxByte[16];
634 | pBoxPermute[ 8] = sBoxByte[ 0];
635 | pBoxPermute[ 9] = sBoxByte[14];
636 | pBoxPermute[10] = sBoxByte[22];
637 | pBoxPermute[11] = sBoxByte[25];
638 | pBoxPermute[12] = sBoxByte[ 4];
639 | pBoxPermute[13] = sBoxByte[17];
640 | pBoxPermute[14] = sBoxByte[30];
641 | pBoxPermute[15] = sBoxByte[ 9];
642 | pBoxPermute[16] = sBoxByte[ 1];
643 | pBoxPermute[17] = sBoxByte[ 7];
644 | pBoxPermute[18] = sBoxByte[23];
645 | pBoxPermute[19] = sBoxByte[13];
646 | pBoxPermute[20] = sBoxByte[31];
647 | pBoxPermute[21] = sBoxByte[26];
648 | pBoxPermute[22] = sBoxByte[ 2];
649 | pBoxPermute[23] = sBoxByte[ 8];
650 | pBoxPermute[24] = sBoxByte[18];
651 | pBoxPermute[25] = sBoxByte[12];
652 | pBoxPermute[26] = sBoxByte[29];
653 | pBoxPermute[27] = sBoxByte[ 5];
654 | pBoxPermute[28] = sBoxByte[21];
655 | pBoxPermute[29] = sBoxByte[10];
656 | pBoxPermute[30] = sBoxByte[ 3];
657 | pBoxPermute[31] = sBoxByte[24];
658 | return pBoxPermute;
659 | }
660 |
661 | function finallyPermute(endByte){
662 | var fpByte = new Array(64);
663 | fpByte[ 0] = endByte[39];
664 | fpByte[ 1] = endByte[ 7];
665 | fpByte[ 2] = endByte[47];
666 | fpByte[ 3] = endByte[15];
667 | fpByte[ 4] = endByte[55];
668 | fpByte[ 5] = endByte[23];
669 | fpByte[ 6] = endByte[63];
670 | fpByte[ 7] = endByte[31];
671 | fpByte[ 8] = endByte[38];
672 | fpByte[ 9] = endByte[ 6];
673 | fpByte[10] = endByte[46];
674 | fpByte[11] = endByte[14];
675 | fpByte[12] = endByte[54];
676 | fpByte[13] = endByte[22];
677 | fpByte[14] = endByte[62];
678 | fpByte[15] = endByte[30];
679 | fpByte[16] = endByte[37];
680 | fpByte[17] = endByte[ 5];
681 | fpByte[18] = endByte[45];
682 | fpByte[19] = endByte[13];
683 | fpByte[20] = endByte[53];
684 | fpByte[21] = endByte[21];
685 | fpByte[22] = endByte[61];
686 | fpByte[23] = endByte[29];
687 | fpByte[24] = endByte[36];
688 | fpByte[25] = endByte[ 4];
689 | fpByte[26] = endByte[44];
690 | fpByte[27] = endByte[12];
691 | fpByte[28] = endByte[52];
692 | fpByte[29] = endByte[20];
693 | fpByte[30] = endByte[60];
694 | fpByte[31] = endByte[28];
695 | fpByte[32] = endByte[35];
696 | fpByte[33] = endByte[ 3];
697 | fpByte[34] = endByte[43];
698 | fpByte[35] = endByte[11];
699 | fpByte[36] = endByte[51];
700 | fpByte[37] = endByte[19];
701 | fpByte[38] = endByte[59];
702 | fpByte[39] = endByte[27];
703 | fpByte[40] = endByte[34];
704 | fpByte[41] = endByte[ 2];
705 | fpByte[42] = endByte[42];
706 | fpByte[43] = endByte[10];
707 | fpByte[44] = endByte[50];
708 | fpByte[45] = endByte[18];
709 | fpByte[46] = endByte[58];
710 | fpByte[47] = endByte[26];
711 | fpByte[48] = endByte[33];
712 | fpByte[49] = endByte[ 1];
713 | fpByte[50] = endByte[41];
714 | fpByte[51] = endByte[ 9];
715 | fpByte[52] = endByte[49];
716 | fpByte[53] = endByte[17];
717 | fpByte[54] = endByte[57];
718 | fpByte[55] = endByte[25];
719 | fpByte[56] = endByte[32];
720 | fpByte[57] = endByte[ 0];
721 | fpByte[58] = endByte[40];
722 | fpByte[59] = endByte[ 8];
723 | fpByte[60] = endByte[48];
724 | fpByte[61] = endByte[16];
725 | fpByte[62] = endByte[56];
726 | fpByte[63] = endByte[24];
727 | return fpByte;
728 | }
729 |
730 | function getBoxBinary(i) {
731 | var binary = "";
732 | switch (i) {
733 | case 0 :binary = "0000";break;
734 | case 1 :binary = "0001";break;
735 | case 2 :binary = "0010";break;
736 | case 3 :binary = "0011";break;
737 | case 4 :binary = "0100";break;
738 | case 5 :binary = "0101";break;
739 | case 6 :binary = "0110";break;
740 | case 7 :binary = "0111";break;
741 | case 8 :binary = "1000";break;
742 | case 9 :binary = "1001";break;
743 | case 10 :binary = "1010";break;
744 | case 11 :binary = "1011";break;
745 | case 12 :binary = "1100";break;
746 | case 13 :binary = "1101";break;
747 | case 14 :binary = "1110";break;
748 | case 15 :binary = "1111";break;
749 | }
750 | return binary;
751 | }
752 | /*
753 | * generate 16 keys for xor
754 | *
755 | */
756 | function generateKeys(keyByte){
757 | var key = new Array(56);
758 | var keys = new Array();
759 |
760 | keys[ 0] = new Array();
761 | keys[ 1] = new Array();
762 | keys[ 2] = new Array();
763 | keys[ 3] = new Array();
764 | keys[ 4] = new Array();
765 | keys[ 5] = new Array();
766 | keys[ 6] = new Array();
767 | keys[ 7] = new Array();
768 | keys[ 8] = new Array();
769 | keys[ 9] = new Array();
770 | keys[10] = new Array();
771 | keys[11] = new Array();
772 | keys[12] = new Array();
773 | keys[13] = new Array();
774 | keys[14] = new Array();
775 | keys[15] = new Array();
776 | var loop = [1,1,2,2,2,2,2,2,1,2,2,2,2,2,2,1];
777 |
778 | for(i=0;i<7;i++){
779 | for(j=0,k=7;j<8;j++,k--){
780 | key[i*8+j]=keyByte[8*k+i];
781 | }
782 | }
783 |
784 | var i = 0;
785 | for(i = 0;i < 16;i ++){
786 | var tempLeft=0;
787 | var tempRight=0;
788 | for(j = 0; j < loop[i];j ++){
789 | tempLeft = key[0];
790 | tempRight = key[28];
791 | for(k = 0;k < 27 ;k ++){
792 | key[k] = key[k+1];
793 | key[28+k] = key[29+k];
794 | }
795 | key[27]=tempLeft;
796 | key[55]=tempRight;
797 | }
798 | var tempKey = new Array(48);
799 | tempKey[ 0] = key[13];
800 | tempKey[ 1] = key[16];
801 | tempKey[ 2] = key[10];
802 | tempKey[ 3] = key[23];
803 | tempKey[ 4] = key[ 0];
804 | tempKey[ 5] = key[ 4];
805 | tempKey[ 6] = key[ 2];
806 | tempKey[ 7] = key[27];
807 | tempKey[ 8] = key[14];
808 | tempKey[ 9] = key[ 5];
809 | tempKey[10] = key[20];
810 | tempKey[11] = key[ 9];
811 | tempKey[12] = key[22];
812 | tempKey[13] = key[18];
813 | tempKey[14] = key[11];
814 | tempKey[15] = key[ 3];
815 | tempKey[16] = key[25];
816 | tempKey[17] = key[ 7];
817 | tempKey[18] = key[15];
818 | tempKey[19] = key[ 6];
819 | tempKey[20] = key[26];
820 | tempKey[21] = key[19];
821 | tempKey[22] = key[12];
822 | tempKey[23] = key[ 1];
823 | tempKey[24] = key[40];
824 | tempKey[25] = key[51];
825 | tempKey[26] = key[30];
826 | tempKey[27] = key[36];
827 | tempKey[28] = key[46];
828 | tempKey[29] = key[54];
829 | tempKey[30] = key[29];
830 | tempKey[31] = key[39];
831 | tempKey[32] = key[50];
832 | tempKey[33] = key[44];
833 | tempKey[34] = key[32];
834 | tempKey[35] = key[47];
835 | tempKey[36] = key[43];
836 | tempKey[37] = key[48];
837 | tempKey[38] = key[38];
838 | tempKey[39] = key[55];
839 | tempKey[40] = key[33];
840 | tempKey[41] = key[52];
841 | tempKey[42] = key[45];
842 | tempKey[43] = key[41];
843 | tempKey[44] = key[49];
844 | tempKey[45] = key[35];
845 | tempKey[46] = key[28];
846 | tempKey[47] = key[31];
847 | switch(i){
848 | case 0: for(m=0;m < 48 ;m++){ keys[ 0][m] = tempKey[m]; } break;
849 | case 1: for(m=0;m < 48 ;m++){ keys[ 1][m] = tempKey[m]; } break;
850 | case 2: for(m=0;m < 48 ;m++){ keys[ 2][m] = tempKey[m]; } break;
851 | case 3: for(m=0;m < 48 ;m++){ keys[ 3][m] = tempKey[m]; } break;
852 | case 4: for(m=0;m < 48 ;m++){ keys[ 4][m] = tempKey[m]; } break;
853 | case 5: for(m=0;m < 48 ;m++){ keys[ 5][m] = tempKey[m]; } break;
854 | case 6: for(m=0;m < 48 ;m++){ keys[ 6][m] = tempKey[m]; } break;
855 | case 7: for(m=0;m < 48 ;m++){ keys[ 7][m] = tempKey[m]; } break;
856 | case 8: for(m=0;m < 48 ;m++){ keys[ 8][m] = tempKey[m]; } break;
857 | case 9: for(m=0;m < 48 ;m++){ keys[ 9][m] = tempKey[m]; } break;
858 | case 10: for(m=0;m < 48 ;m++){ keys[10][m] = tempKey[m]; } break;
859 | case 11: for(m=0;m < 48 ;m++){ keys[11][m] = tempKey[m]; } break;
860 | case 12: for(m=0;m < 48 ;m++){ keys[12][m] = tempKey[m]; } break;
861 | case 13: for(m=0;m < 48 ;m++){ keys[13][m] = tempKey[m]; } break;
862 | case 14: for(m=0;m < 48 ;m++){ keys[14][m] = tempKey[m]; } break;
863 | case 15: for(m=0;m < 48 ;m++){ keys[15][m] = tempKey[m]; } break;
864 | }
865 | }
866 | return keys;
867 | }
--------------------------------------------------------------------------------