1.调整路由命名
2.api中添加Caesar算法
This commit is contained in:
parent
adf533c594
commit
b28732d3ef
51
apps/api/common.py
Normal file
51
apps/api/common.py
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
class CaesarCypherClass:
|
||||||
|
"""
|
||||||
|
恺撒密码,提供以恺撒密码方法进行加密及解密的方法,加密方法使用CaesarEncode()函数,解密方法使用CaesarDecode()函数
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
pass
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def caesar_encode(s):
|
||||||
|
"""
|
||||||
|
恺撒密码加密方法,需要提供需要加密的明文。
|
||||||
|
"""
|
||||||
|
s_encode = ''
|
||||||
|
for c in s:
|
||||||
|
if 'a' <= c <= 'z':
|
||||||
|
s_encode += chr(ord('a') + (ord(c) - ord('a') + 3) % 26)
|
||||||
|
elif 'A' <= c <= 'Z':
|
||||||
|
s_encode += chr(ord('A') + (ord(c) - ord('A') + 3) % 26)
|
||||||
|
elif 0x4E00 <= ord(c) <= 0x9FA5:
|
||||||
|
s_encode += chr(ord(c) + 3)
|
||||||
|
elif '0' <= c <= '9':
|
||||||
|
s_encode += chr(ord('0') + (ord(c) - ord('0') + 3) % 10)
|
||||||
|
else:
|
||||||
|
s_encode += c
|
||||||
|
return s_encode
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def caesar_decode(s):
|
||||||
|
"""
|
||||||
|
恺撒密码解密方法,需要提供需要解密的密文。
|
||||||
|
"""
|
||||||
|
s_decode = ''
|
||||||
|
for c in s:
|
||||||
|
if 'a' <= c <= 'z':
|
||||||
|
s_decode += chr(ord('a') + (ord(c) - ord('a') - 3) % 26)
|
||||||
|
elif 'A' <= c <= 'Z':
|
||||||
|
s_decode += chr(ord('A') + (ord(c) - ord('A') - 3) % 26)
|
||||||
|
elif 0x4E00 <= ord(c) <= 0x9FA5:
|
||||||
|
s_decode += chr(ord(c) - 3)
|
||||||
|
elif '0' <= c <= '9':
|
||||||
|
s_decode += chr(ord('0') + (ord(c) - ord('0') - 3) % 10)
|
||||||
|
else:
|
||||||
|
s_decode += c
|
||||||
|
return s_decode
|
||||||
|
|
||||||
|
|
||||||
|
class Base64CypherClass:
|
||||||
|
"""
|
||||||
|
Base64的加解密算法,最简单的加密方式,可加密短的文字、小图片、小文件,图片文件大小不宜超过10M
|
||||||
|
"""
|
@ -2,5 +2,5 @@ from django.urls import path
|
|||||||
from apps.api import views
|
from apps.api import views
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path("getconfig/", views.getconfig, name="getconfig"),
|
path("getconfig/", views.get_config, name="getconfig"),
|
||||||
]
|
]
|
||||||
|
@ -1,15 +1,25 @@
|
|||||||
from django.shortcuts import HttpResponse
|
from django.shortcuts import HttpResponse
|
||||||
from apps.api import models as m_api
|
from apps.api import models as m_api
|
||||||
from django.views.decorators.http import require_http_methods, require_POST, require_GET
|
from django.views.decorators.http import require_http_methods, require_POST, require_GET
|
||||||
|
from apps.api.common import CaesarCypherClass
|
||||||
|
|
||||||
|
|
||||||
# Create your views here.
|
# Create your views here.
|
||||||
@require_POST
|
@require_POST
|
||||||
def getconfig(request):
|
def get_config(request):
|
||||||
try:
|
try:
|
||||||
identity = request.POST.get("param")
|
identity = request.POST.get("param")
|
||||||
param = m_api.SysConfig.objects.filter(identity=identity).first().param
|
param = m_api.SysConfig.objects.filter(identity=identity).first().param
|
||||||
return HttpResponse(param)
|
return HttpResponse(param)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"报错了:{e}")
|
print(f"报错了:{e}")
|
||||||
return HttpResponse("报错了")
|
return HttpResponse(f"报错了:{e}")
|
||||||
|
|
||||||
|
|
||||||
|
@require_POST
|
||||||
|
def add_config(request):
|
||||||
|
try:
|
||||||
|
pass
|
||||||
|
except Exception as e:
|
||||||
|
print(f"报错了:{e}")
|
||||||
|
return HttpResponse(f"报错了:{e}")
|
||||||
|
@ -2,7 +2,7 @@ from django.urls import path
|
|||||||
from apps.auth import views
|
from apps.auth import views
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path("gettoken/", views.gettoken, name="getToken"),
|
path("gettoken/", views.get_token, name="getToken"),
|
||||||
path("searchuser/", views.search_user, name="searchuser"),
|
path("searchuser/", views.search_user, name="searchuser"),
|
||||||
path("adduser/", views.add_user, name="addUser"),
|
path("adduser/", views.add_user, name="addUser"),
|
||||||
path("login/", views.login_user, name="loginUser"),
|
path("login/", views.login_user, name="loginUser"),
|
||||||
|
@ -9,7 +9,7 @@ from django.contrib.auth.hashers import make_password, check_password
|
|||||||
|
|
||||||
# Create your views here.
|
# Create your views here.
|
||||||
@require_GET
|
@require_GET
|
||||||
def gettoken(request):
|
def get_token(request):
|
||||||
"""
|
"""
|
||||||
获取token
|
获取token
|
||||||
:param request:
|
:param request:
|
||||||
|
Loading…
Reference in New Issue
Block a user