| import numpy as np
|
| import pandas as pd
|
| import os
|
|
|
|
|
|
|
| INPUT_DIR = r"Device9174_AES/3m_9174_11k-1"
|
|
|
|
|
| OUTPUT_FILE = "preview_AES_3m.parquet"
|
|
|
|
|
| PREVIEW_ROWS = 1000
|
|
|
|
|
|
|
|
|
| def to_hex_string(arr):
|
| """辅助函数:将整数数组转换为 Hex 字符串 (e.g., 'A1B2...'),方便阅读"""
|
|
|
| return [''.join(f'{x:02X}' for x in row) for row in arr]
|
|
|
|
|
| def create_preview_parquet():
|
| print(f"正在读取 NPY 文件: {INPUT_DIR} ...")
|
|
|
|
|
|
|
|
|
| try:
|
| traces = np.load(os.path.join(INPUT_DIR, "100_traces.npy"))[:PREVIEW_ROWS]
|
| pts = np.load(os.path.join(INPUT_DIR, "100_pt.npy"))[:PREVIEW_ROWS]
|
| cts = np.load(os.path.join(INPUT_DIR, "100_ct.npy"))[:PREVIEW_ROWS]
|
|
|
| keys = np.load(os.path.join(INPUT_DIR, "100_10th_roundkey.npy"))[:PREVIEW_ROWS]
|
|
|
| print(f"数据加载完毕。截取前 {PREVIEW_ROWS} 行。")
|
| print(f"波形形状: {traces.shape}")
|
|
|
|
|
|
|
| df = pd.DataFrame({
|
| "trace": list(traces),
|
| "plaintext": to_hex_string(pts),
|
| "ciphertext": to_hex_string(cts),
|
| "key (10th round)": to_hex_string(keys),
|
| "label": "AES_3m_Avg100"
|
| })
|
|
|
|
|
| df.to_parquet(OUTPUT_FILE, index=False)
|
| print(f"✅ 转换成功!文件已保存为: {OUTPUT_FILE}")
|
| print("请将此文件上传到 Hugging Face 仓库的根目录。")
|
|
|
| except FileNotFoundError as e:
|
| print(f"❌ 找不到文件: {e}")
|
| except Exception as e:
|
| print(f"❌ 发生错误: {e}")
|
|
|
|
|
| if __name__ == "__main__":
|
| create_preview_parquet() |