diff --git a/break_script/break_aes.jl b/break_script/break_aes.jl index 7e69545..9659997 100755 --- a/break_script/break_aes.jl +++ b/break_script/break_aes.jl @@ -4,9 +4,17 @@ include("util.jl") include("sbox.jl") include("plotutils.jl") +function parse_csv(filename) + println("Starting parsing") + data = CSV.read(filename, header=0) + println("Parsing done") + plaintexts::Matrix{UInt8} = convert(Matrix{UInt8}, data[:, 1:16]) + timings::Matrix{UInt32} = convert(Matrix{UInt32}, data[:, 17:17]) + return plaintexts, timings +end + function break_aes() - plaintexts = load_file("plaintexts.dat", UInt8)[1:10_000, :] - timings = load_file("timings.dat", UInt32)[1:10_000] + plaintexts, timings = parse_csv("timing.csv") t_values = Vector{Float64}(undef, 0x100) for key=0:0xFF msb_set = (sbox[(plaintexts[:, 1] .⊻ key) .+ 1] .& 0x80) .!= 0 diff --git a/break_script/parse_csv.jl b/break_script/parse_csv.jl deleted file mode 100755 index f6e871a..0000000 --- a/break_script/parse_csv.jl +++ /dev/null @@ -1,42 +0,0 @@ -#!/usr/bin/env julia - -import CSV -using Formatting - -function parse_csv(filename) - println("Starting parsing") - data = CSV.read(filename, header=0) - println("Parsing done") - plaintexts::Matrix{UInt8} = convert(Matrix{UInt8}, data[:, 1:16]) - timings::Matrix{UInt32} = convert(Matrix{UInt32}, data[:, 17:17]) - write_data("plaintexts.dat", plaintexts) - write_data("timings.dat", timings) -end - -function write_data(destination, data) - open(destination, "w") do file - field_size::UInt8 = sizeof(eltype(data)) - rows::UInt64 = size(data, 1) - cols::UInt64 = size(data, 2) - write(file, field_size); - write(file, rows) - write(file, cols) - write(file, data) - end -end - -function load_file(filename, type::Type{T})::Matrix{T} where T - open(filename, "r") do file - field_size = read(file, UInt8) - if field_size != sizeof(T) - throw(ArgumentError(format("Expected type of size {:d} but passed type '{}' has size {:d}", field_size, T, sizeof(T)))) - end - rows = read(file, UInt64) - cols = read(file, UInt64) - data = Matrix{T}(undef, rows, cols) - read!(file, data) - return data - end -end - -@time parse_csv("timing.csv")