生成 IPv6 后缀

问题描述

请我在一个 IPv6 项目上工作:我必须使用哈希函数 XOR 生成加密的 IPv6 并使用 DES 加密以生成一个 IPv6 后缀地址,我可以将其添加到已知前缀以形成 IPv6 地址,因此我的代码是:

import hashlib
from datetime import datetime
from pyDes import *
import ipaddress

# This is the source IPv6 Address SA :
SA = "200104701f1300ae0000000000000010".encode()

# Here is the HASH for the SA to get the H_SA :
HA_MD5 = hashlib.md5()
HA_MD5.update(SA)
H_SA = HA_MD5.digest()
print("The hashed IPv6 @ H_SA is : ",H_SA,len(H_SA))
# output is : The hashed IPv6 @ H_SA is :  b'\r\xee\x0f\tJb\x08\xee\x02\x1c\x04nE\xfe\x16\xfa' 16

# Generating the timestamp to form the salt :
Now = datetime.Now()
timestamp = str(datetime.timestamp(Now)).encode()
print("The timestamp is : ",timestamp,len(timestamp))
# output is : The timestamp is :  b'1616255227.435759' 17

# The XOR function :
def xor_bytes(H_SA,timestamp):
    lenght = min(len(H_SA),len(timestamp))
    return bytes([H_SA[i] ^ timestamp[i] for i in range(lenght)])

# XOR the timestamp (salt) with the H_SA to get the P_SA:
P_SA = xor_bytes(H_SA,timestamp)
print("The XOR of H_SA & timestamp is P_SA : ",P_SA,len(P_SA))
# output is : The XOR of H_SA & timestamp is P_SA :  b'<\xd8>?xW=\xdc0+*Zv\xcb!\xcf' 16

# Encrypt the P_SA with DES encryption :
key = "IoT_IPv6"
IV = bytes([0]*8)
ENCRYPT_DES = des(key,CBC,IV,pad=None,padmode=PAD_PKCS5)
DA_SFX = ENCRYPT_DES.encrypt(P_SA)
print(DA_SFX,len(DA_SFX))
# output is : b'\xe3\xf0\xec\x97\x85=M\x95\x00\xc14\x9aw\xa2\x8b\xb9\xb0y\x1eY\xdf\r\xc1,' 24

我的问题是:如何从最后一个输出 (DA_SFX) 生成后缀 IPv6 地址,知道我必须保留所有 DA_SFX,以允许目标服务器反转所有过程。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)