Created
October 4, 2017 21:28
-
-
Save rot256/c546752a25dedcf6f7f80ce10a419fd2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # setup & collect | |
| from random import randrange | |
| S = [ | |
| 0xC, 0x5, 0x6, 0xB, | |
| 0x9, 0x0, 0xA, 0xD, | |
| 0x3, 0xE, 0xF, 0x8, | |
| 0x4, 0x7, 0x1, 0x2 | |
| ] | |
| def hw(v): | |
| return bin(v).count('1') | |
| K = 0xB | |
| ins = [randrange(0, 16) for _ in range(50)] | |
| out = map(lambda x: S[x^K], ins) | |
| met = map(hw, out) | |
| # attack | |
| from scipy.stats.stats import pearsonr | |
| for k in range(16): | |
| outp = map(lambda x: S[x^k], ins) | |
| metc = map(hw, outp) | |
| corr, _ = pearsonr(metc, met) | |
| print hex(k), corr |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment