Monday, December 21, 2015

Simon Cipher for 32/64.

The complete iteration for the Simon Cipher where K is the key expansion and C is the encryption block. Using the key block and test block specified by the Simon and Speck specification:
key value: 1918111009080100
test block: 65656877
result: c69be9bb

k[00] 1918 1110 0908 0100 
c[00] 6565 6877 
k[01] 71c3 1918 1110 0908 
c[01] bca2 6565 
k[02] b649 71c3 1918 1110 
c[02] bee3 bca2 
k[03] 56d4 b649 71c3 1918 
c[03] 37ba bee3 
k[04] e070 56d4 b649 71c3 
c[04] 5327 37ba 
k[05] f15a e070 56d4 b649 
c[05] 2ca6 5327 
k[06] c535 f15a e070 56d4 
c[06] 57fa 2ca6 
k[07] dd94 c535 f15a e070 
c[07] 8fcf 57fa 
k[08] 4010 dd94 c535 f15a 
c[08] 873b 8fcf 
k[09] 250a 4010 dd94 c535 
c[09] 687c 873b 
k[10] 6f66 250a 4010 dd94 
c[10] b397 687c 
k[11] e96b 6f66 250a 4010 
c[11] 7c95 b397 
k[12] 4bd8 e96b 6f66 250a 
c[12] 90fa 7c95 
k[13] 0fe5 4bd8 e96b 6f66 
c[13] 3ae5 90fa 
k[14] 7c47 0fe5 4bd8 e96b 
c[14] 7102 3ae5 
k[15] e0ef 7c47 0fe5 4bd8 
c[15] 1587 7102 
k[16] 3e21 e0ef 7c47 0fe5 
c[16] 6fc2 1587 
k[17] 065b 3e21 e0ef 7c47 
c[17] 676f 6fc2 
k[18] 438c 065b 3e21 e0ef 
c[18] c07e 676f 
k[19] f26a 438c 065b 3e21 
c[19] 86bb c07e 
k[20] b5c0 f26a 438c 065b 
c[20] edb7 86bb 
k[21] 8609 b5c0 f26a 438c 
c[21] a552 edb7 
k[22] 9f8e 8609 b5c0 f26a 
c[22] 79d4 a552 
k[23] d8bf 9f8e 8609 b5c0 
c[23] 6041 79d4 
k[24] 09ac d8bf 9f8e 8609 
c[24] 0d11 6041 
k[25] e812 09ac d8bf 9f8e 
c[25] c20c 0d11 
k[26] 2710 e812 09ac d8bf 
c[26] 9eac c20c 
k[27] 2caa 2710 e812 09ac 
c[27] 4c19 9eac 
k[28] 8d14 2caa 2710 e812 
c[28] bf65 4c19 
k[29] fa04 8d14 2caa 2710 
c[29] 3d16 bf65 
k[30] 32f2 fa04 8d14 2caa 
c[30] 7e01 3d16 
k[31] 7db9 32f2 fa04 8d14 
c[31] e9bb 7e01 
k[32] 4d83 7db9 32f2 fa04 
c[32] c69b e9bb
The test vector that was provided by the NSA seems to be explicitly aligned to hit the critical bits in the key expansion. Pretty nice piece of mathematics.

Saturday, December 19, 2015

LaTeX: Center rotated text vertically.

There seems to be 100s of ways to do this. I only had 2 columns to tweak, and this worked the best:
\raisebox{2.5\normalbaselineskip}[0pt][0pt]{\rotatebox[origin=c]{90}{Rotated Text}}
The 2.5 needs to be adjusted for the height of the row.

Sunday, December 13, 2015

removing commas from a line of text

who knows why it took me four times to get it correct:

echo "1,1,1,1,1,0,1,0,0,0,1,0,0,1,0,1,0,1,1,0,0,0,0,1,1,1,0,0,1,1,0,1,1,1,1,1,0,1,0,0,0,1,0,0,1,0,1,0,1,1,0,0,0,0,1,1,1,0,0,1,1,0" | sed 's/,//g'
which resulted in:
11111010001001010110000111001101111101000100101011000011100110

Tuesday, December 1, 2015

Finding files with BASH and excluding some from the list.

I wanted to copy some files from the current directory to another based on file type, and file name. Bash 4.0 has some great things, such as globs:
shopt -s globstar nullglob extglob
I do not have Bash 4.0; I have Bash 3.2. So how does one list all files of a type, and then exclude some. The fastest way I found was to not use any external tools, but use case statements:
for f in *; do
  case "$f" in
     *.c |*.h | *.data| *.sh | Makefile) 
     # it's a valid filetype
          case "$f" in
          exportcode.sh | r.sh | project.report.sh)
          #exclude list is above
             ;;
          *)
             echo $f  # output the file name
             ;;
          esac   
         ;;
         *)
  # it's not
  ;;
   esac
done
The above code finds every file in the directory that is a .c .h .data .sh or Makefile and then excludes the file exportcode.sh, r.sh and project.report.sh. The resulting files are output via the "echo $f".