aboutsummaryrefslogtreecommitdiffstats
path: root/sources/apps/QUAC-TRNG/scripts/convert_ent.py
diff options
context:
space:
mode:
authorAtaberk <olgunataberk@gmail.com>2022-09-25 17:22:03 +0200
committerAtaberk <olgunataberk@gmail.com>2022-09-25 17:22:03 +0200
commitdc0b3db1b4f1895a07e5fe280ee3790e87f97b9f (patch)
treeb47203aa281bdd959def4451c84d310cd9cf2e12 /sources/apps/QUAC-TRNG/scripts/convert_ent.py
downloaddram-bender-dc0b3db1b4f1895a07e5fe280ee3790e87f97b9f.tar.gz
Initial commit
Diffstat (limited to 'sources/apps/QUAC-TRNG/scripts/convert_ent.py')
-rw-r--r--sources/apps/QUAC-TRNG/scripts/convert_ent.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/sources/apps/QUAC-TRNG/scripts/convert_ent.py b/sources/apps/QUAC-TRNG/scripts/convert_ent.py
new file mode 100644
index 0000000..b2c66ea
--- /dev/null
+++ b/sources/apps/QUAC-TRNG/scripts/convert_ent.py
@@ -0,0 +1,32 @@
+import os
+import argparse
+from numpy import array
+
+parser = argparse.ArgumentParser(description = "Run this script to preprocess entropy files")
+parser.add_argument('indir', help="Path to entropy files")
+args = parser.parse_args()
+
+files = []
+for fname in os.listdir(args.indir):
+ files.append(fname)
+
+for file in files:
+ print("Processing:", file)
+ # Add this placement
+ fpath = os.path.normpath(args.indir + '/' + file)
+ infile = open(fpath,'r')
+ wfile = file.split('.')[0] + '_floats.bin'
+ wfpath = os.path.normpath(args.indir + '/' + wfile)
+ output_file = open(wfpath, 'wb')
+
+ lines = infile.readlines()
+
+ # First row reserved for metadata
+ for lidx in range(1,len(lines)):
+ line = lines[lidx].strip()
+ split = line.split()
+ elements = [float(i) for i in split[1:]]
+ a = array(elements,'float32')
+ a.tofile(output_file)
+
+ output_file.close() \ No newline at end of file