Skip to content

Instantly share code, notes, and snippets.

@breuderink
Last active September 19, 2017 18:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save breuderink/733e2f8d626869ccde3520cdba530bde to your computer and use it in GitHub Desktop.
Save breuderink/733e2f8d626869ccde3520cdba530bde to your computer and use it in GitHub Desktop.
The hunt for the most normal scrambler for SORM features.
from scipy import linalg, stats
import numpy as np
from functools import reduce
N = 16
def eval_scrambler(pat, reps=1):
pat = np.atleast_1d(pat)
D = np.diag(np.where(pat==1, -1, 1))
H = linalg.hadamard(pat.size)
return reduce(np.dot, [H] + [D, H] * reps)
best = -np.inf
perfs = []
for i in range(0, 1<<N):
pat = np.asarray([(i >> b) & 1 for b in range(N)])
T = eval_scrambler(pat, reps=2)
vals = np.unique(T)
(_, perf) = stats.shapiro(T.flatten())
perfs.append(perf)
if perf > best:
best = perf
print('%s -> %s' % (pat, perf))
print(stats.itemfreq(perfs))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment