信息安全技术课程设计
学艺不精,自己搞了一晚上没整出来放弃了,还是看着大佬的思路按自己能理解的方式写了一下,运行没问题,将就着看。
第七题
题目七:图形验证模拟
1、开发一个手机锁屏的图形验证程序,以字符命令行形式来实现要求完成的功能有:
2、登录时输入用户名;
3、输入4*4坐标下的图形点位置,用字符方式输入;
4、输入完成后实现在服务器端对图形进行验证;
5、至少有三个以上的用户验证。
# python -u "d:\课程设计A\py7\client7.py"
import socket
import re
c = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
host = socket.gethostname()
port = 12345
bufSize = 1024
c.connect((host, port))
list = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
userName = input("Input username:")
c.send(userName.encode())
kk = re.compile(r'\d+')
while True:
value = input("请输入set(a,b)验证图形,输入'end'开始验证\n")
if value != "end":
x = kk.findall(value)
sum = (int(x[0])-1)*4 + int(x[1])-1
list[sum] = 1
for i in range(0, 16):
if list[i] == 0:
print("o", end="")
else:
print("x", end="")
if i % 4 == 3:
print("")
else:
list = map(str, list)
userPass = ""
userPass = "".join(list)
c.send(userPass.encode())
back = c.recv(bufSize).decode()
if back == "Successful":
print("Successful")
break
else:
print("Incorrect user name or password")
c.close()
# python -u "d:\课程设计A\py7\server7.py"
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
host = socket.gethostname()
port = 12345
bufSize = 1024
s.bind((host, port))
s.listen(5)
users = {"admin": "1111000000000000",
"aaa": "1000100010001000",
"bbb": "1000010000100001",
"ccc": "0001000100010001"
}
print("Waiting for the link...")
c, addr = s.accept()
print("In authentication...")
userName = c.recv(bufSize).decode()
while True:
userPass = c.recv(bufSize).decode()
if users[userName] == userPass:
c.send("Successful".encode())
print("Successful")
break
else:
c.send("Incorrect user name or password".encode())
c.close()
s.close()