**360点睛平台,密码加密-python版**

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import hashlib
from Crypto.Cipher import AES
import base64
from binascii import b2a_hex

def create_md5_pwd(password):
    m = hashlib.md5()
    b = password.encode(encoding='utf-8')
    m.update(b)
    md5_pwd = m.hexdigest()
    return md5_pwd

class PrpCrypt(object):

    def __init__(self, API_SECRET):
        self.key = API_SECRET[:16].encode('gbk')  # 密匙
        self.iv = API_SECRET[16:].encode('gbk')  # 密匙向量

    def encrypt(self,text):
        # 加密
        mycipher = AES.new(self.key, AES.MODE_CBC, self.iv)
        # 加密的明文长度必须为16的倍数,如果长度不为16的倍数,则需要补足为16的倍数
        # 将iv(密钥向量)加到加密的密文开头,一起传输
        ciphertext = self.iv + mycipher.encrypt(text.encode())
        return ciphertext  # 加密

    def decrypt(self,text):
        # 解密
        mydecrypt = AES.new(self.key, AES.MODE_CBC, text[:16])
        decrypttext = mydecrypt.decrypt(text[16:])
        decrypt_pwd = decrypttext.decode()  # 解密后数据
        return decrypt_pwd


if __name__ == '__main__':
    password = '密码11111111'
    API_SECRET = "22222222222"  # 点睛提供
    text = create_md5_pwd(password)
    pc = PrpCrypt(API_SECRET)  # 初始化密匙
    ciphertext = pc.encrypt(text)
    e = b2a_hex(ciphertext)[32:].decode()
    d = pc.decrypt(ciphertext)
    print('加密后:' + e)
    print('解密后:' + d)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
下面是使用 OpenCV 和 dlib 库实现截取眼和嘴巴的 Python 代码: ```python import cv2 import dlib # 加载模型 detector = dlib.get_frontal_face_detector() predictor = dlib.shape_predictor('shape_predictor_68_face_landmarks.dat') # 加载图像 img = cv2.imread('test.jpg') gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) # 检测人脸 faces = detector(gray) # 遍历每张脸并截取眼和嘴巴 for face in faces: # 获取关键点 landmarks = predictor(gray, face) # 截取左眼 left_eye_pts = [(landmarks.part(36).x, landmarks.part(36).y), (landmarks.part(37).x, landmarks.part(37).y), (landmarks.part(38).x, landmarks.part(38).y), (landmarks.part(39).x, landmarks.part(39).y), (landmarks.part(40).x, landmarks.part(40).y), (landmarks.part(41).x, landmarks.part(41).y)] left_eye_mask = np.zeros(img.shape[:2], dtype=np.uint8) cv2.drawContours(left_eye_mask, [np.array(left_eye_pts)], -1, (255, 255, 255), -1, cv2.LINE_AA) left_eye = cv2.bitwise_and(img, img, mask=left_eye_mask) # 截取右眼 right_eye_pts = [(landmarks.part(42).x, landmarks.part(42).y), (landmarks.part(43).x, landmarks.part(43).y), (landmarks.part(44).x, landmarks.part(44).y), (landmarks.part(45).x, landmarks.part(45).y), (landmarks.part(46).x, landmarks.part(46).y), (landmarks.part(47).x, landmarks.part(47).y)] right_eye_mask = np.zeros(img.shape[:2], dtype=np.uint8) cv2.drawContours(right_eye_mask, [np.array(right_eye_pts)], -1, (255, 255, 255), -1, cv2.LINE_AA) right_eye = cv2.bitwise_and(img, img, mask=right_eye_mask) # 截取嘴巴 mouth_pts = [(landmarks.part(48).x, landmarks.part(48).y), (landmarks.part(49).x, landmarks.part(49).y), (landmarks.part(50).x, landmarks.part(50).y), (landmarks.part(51).x, landmarks.part(51).y), (landmarks.part(52).x, landmarks.part(52).y), (landmarks.part(53).x, landmarks.part(53).y), (landmarks.part(54).x, landmarks.part(54).y), (landmarks.part(55).x, landmarks.part(55).y), (landmarks.part(56).x, landmarks.part(56).y), (landmarks.part(57).x, landmarks.part(57).y), (landmarks.part(58).x, landmarks.part(58).y), (landmarks.part(59).x, landmarks.part(59).y), (landmarks.part(60).x, landmarks.part(60).y), (landmarks.part(61).x, landmarks.part(61).y), (landmarks.part(62).x, landmarks.part(62).y), (landmarks.part(63).x, landmarks.part(63).y), (landmarks.part(64).x, landmarks.part(64).y), (landmarks.part(65).x, landmarks.part(65).y), (landmarks.part(66).x, landmarks.part(66).y), (landmarks.part(67).x, landmarks.part(67).y)] mouth_mask = np.zeros(img.shape[:2], dtype=np.uint8) cv2.drawContours(mouth_mask, [np.array(mouth_pts)], -1, (255, 255, 255), -1, cv2.LINE_AA) mouth = cv2.bitwise_and(img, img, mask=mouth_mask) # 显示结果 cv2.imshow('Left Eye', left_eye) cv2.imshow('Right Eye', right_eye) cv2.imshow('Mouth', mouth) cv2.waitKey(0) cv2.destroyAllWindows() ``` 在上面的代码中,我们首先加载了训练好的人脸检测器和面部关键点检测器。然后,我们加载了一张图像,并将其转换为灰度图像。接下来,我们使用人脸检测器检测出图像中的所有人脸,并使用面部关键点检测器获取每个人脸的面部关键点。最后,我们根据面部关键点截取出眼和嘴巴的部分,并在窗口中显示结果。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值