<jupyter_start><jupyter_text>Hamming weight extractor- Extracts the Hamming weight of the state after the SBox in the first round.- Appends a hamming weight column to the ASCAD file.<jupyter_code>ASCAD_RAW = ASCADData.raw()
IXS = np.arange(len(ASCAD_RAW['traces']))
profile_mask = np.ones(len(IXS)).astype(bool)
profile_mask[2::3] = False
rng = default_rng(seed=42)
num_traces = 10000
detect_ixs = IXS[profile_mask][:num_traces]
lim = max(detect_ixs)
RAW_TRACES = ASCAD_RAW['traces']
RAW_META = ASCAD_RAW['metadata']

full_key_ix = 1
plaintext_ix = 0

trace_len = ASCAD_RAW['traces'].shape[1]
traces = np.zeros((num_traces, trace_len), dtype=np.int8)

profile_key, profile_plain = np.zeros((num_traces, 16), dtype=np.uint8), np.zeros((num_traces, 16), dtype=np.uint8)

for i, ascad_i in tqdm(zip(range(num_traces), detect_ixs), total=num_traces):
      traces[i] = RAW_TRACES[ascad_i]
      profile_key[i] = RAW_META[ascad_i][full_key_ix]
      profile_plain[i] = RAW_META[ascad_i][plaintext_ix]

ASCAD_RAW.close()<jupyter_output>100%|██████████| 10000/10000 [00:22<00:00, 451.66it/s]<jupyter_text>Calculate full intermediate states from AESBased on plaintext and key metadata.<jupyter_code>profile_states = full_states(np.array(profile_plain), np.array(profile_key))
profile_hw = hamming_weights(profile_states[:, 0, 0])
profile_hw_masked = hamming_weights(profile_states[:, 0, 2])
sns.lineplot(data={
    "Profile hw distribution": np.bincount(profile_hw),
    "Attack hw distribution": np.bincount(profile_hw_masked),
})
traces
tvla_x, tvla_y = prepare_tvla(traces, profile_hw)
PVS = rho_test(tvla_x, tvla_y)
STEP = 10
IX = np.arange(len(PVS[0]), step=STEP)
G = sns.lineplot(data=pd.DataFrame({"$p$-values": PVS[0][::STEP]}, index=IX))

START = 45500
END = START + 1977 * 3
HIGHLIGHT = sns.color_palette()[1]
plt.axvspan(START, END, color=HIGHLIGHT, alpha=.5, zorder=100)
sns.lineplot(y=[10 ** -5] * len(IX), x = IX, color="#FF000080", linestyle="--", label="Threshold", zorder=101)
G.set(yscale="log", ylim=(1, 10 ** -150), xlim=(0, max(IX)), xlabel="Sample point index", ylabel="Confidence values ($p$)",
      title="PoI selection on the ASCAD dataset, using the $\\rho$-test")

handles, labels = G.get_legend_handles_labels()
patch = patches.Patch(color=HIGHLIGHT, alpha=.5, label='Selection')
handles.append(patch)
plt.legend(handles=handles)
store_sns(G, "poi-ascad-none")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1596847781003733, 'fraction_numerical': 0.036499377851513894, 'mean_word_length': 6.908196721311476, 'pattern_counts': {'":': 3, '<': 9, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '597796', 'license': 'MIT', 'n_tokens_mistral': 1044, 'n_tokens_neox': 954, 'n_words': 180, 'path': 'report/chapter-3/detection/ascad.ipynb', 'repo_name': 'ccberg/LA', 'size': '2411'}