4 This file is part of the AVR-Crypto-Lib.
5 Copyright (C) 2006-2015 Daniel Otte (bg@nerilex.org)
7 This program is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 shift_values = [ 5, 36, 13, 58, 26, 53, 11, 59,
22 56, 28, 46, 44, 20, 35, 42, 50,
24 38, 48, 34, 26, 33, 39, 29, 33,
25 30, 20, 14, 12, 49, 27, 26, 51,
26 50, 43, 15, 58, 8, 41, 11, 39,
27 53, 31, 27, 7, 42, 14, 9, 35,
29 55, 25, 33, 34, 28, 17, 58, 47,
30 43, 25, 8, 43, 7, 6, 7, 49,
31 37, 46, 18, 25, 47, 18, 32, 27,
32 40, 13, 57, 60, 48, 25, 45, 58,
33 16, 14, 21, 44, 51, 43, 19, 37,
34 22, 13, 12, 9, 9, 42, 18, 48,
35 38, 52, 32, 59, 35, 40, 2, 53,
36 12, 57, 54, 34, 41, 15, 56, 56 ]
38 def transform_shift(value)
39 byteshift = (value+3)/8
45 return [singleshift, byteshift]
48 def transform_singleshift(value)
52 return 0x08+(value*-1)
61 a = transform_shift(v)
62 printf("%2d = %2d * 8 %+2d\n", v, a[1], a[0])
67 puts("byteshift histogram:")
69 printf("%d: %4d\n", i, bs_hist[i])
72 puts("singleshift histogram:")
74 printf("%+d: %4d\n", i, ss_hist[i])
78 (0..shift_values.length-1).each{|i|
79 puts " for 256 bit:" if i==0
80 puts " for 512 bit:" if i==16
81 puts " for 1024 bit:" if i==16+32
83 a = transform_shift(shift_values[i])
84 a[0] = transform_singleshift(a[0])
85 printf("0x%01x%01x, ", a[1], a[0])
90 puts "\ntransformed (decryption):"
91 (0..shift_values.length-1).each{|i|
92 puts " for 256 bit:" if i==0
93 puts " for 512 bit:" if i==16
94 puts " for 1024 bit:" if i==16+32
96 a = transform_shift(shift_values[(i/8)*8+7-(i%8)])
97 a[0] = transform_singleshift(a[0])
98 printf("0x%01x%01x, ", a[1], a[0])