Hello!
Yes I know that I said in my last post that I wasn't going to post again in Blogger... I decided to post one last time because of several emails that I have received about why I am done with the New Google Interface and Google in general. Here is why I hate Google and the Blogger interface that they have destroyed.
I'm not going to elaborate much so here is the simple explanation in no particular order:
1) The New Interface Is Hard To Read: The new Google interface is all white space with black text making it hard on the eyes especially in low light, which is how I like to use the computer in the evening. I can't easily see what I am typing. The eye strain is obvious (unless you work for Google). Why do this, let's make it hard for everyone to read!!!!!
2) The menus are down the left side instead of across the top, a very unnatural place to look for stuff. Don't we all gravitate to the top of the window to look for "File" or "Edit" or any other common task? It's become natural to scan the top of the page or window to look for the options that are available... let's "Save" what we are doing (look to the top of the window); "Edit" the text or font (look to the top of the window)... Or... "I want to do something... it should be in the Tool's menu.... at the top.... where the hell is it????... not at the top!!! It's down the side!!!".... Why???
3) All the menu selections are now different. OK I get it, lets take what used to be at the top and put it down the left side of the window... But wait, you didn't do that did you? What used to be a simple click at the top is now buried in some complicated maze of stupidity in your "improved" left hand side bar menu system. Why?? Please tell me why you would do this?
4) Login page. The "blogs I follow" info is bigger and takes up more screen space than my own blog information when I log in. Why is that? Did I log in to see what my buddies are writing or did I login in to create a new post. This is after all about what I want to write about.
Google think tank: "Let's put all the stuff our user's friends are writing about on our users home page because we think our user wants to see that"... When I log in I want to see what is going on with my blog first, everyone else can wait until I'm ready to click on something (CLICK AT THE TOP) and see what other Bloggers are writing about.
Why can't I see on my own login page my own Blog info? Why???
- Side note: Blogging is a Web Log about me (or you) want to write about. Blogs that I follow are secondary, in other words when I log in TO MY BLOG I expect to see info about MY BLOG and not other people, I can and will get to them later (Unless I use a Google product, because then I have to see everything BUT then things I want to see).... WHY?????
5) Scroll bar and Omnibar. Do you use Google chrome? Good luck if you do. Chrome has a very stupid and annoying scroll bar that is inverted in relation to every sane person in the world (unless you are a idiot). The scroll bar is "dark" where you have to click to scroll, exactly backwards from every other software product I have ever used.
Here is what this amounts to:
Google engineer says " Lets be different and mix it up a bit, lets invert the colors on the scroll bar, everyone will love it"...
A real world example: "Let's reverse the gas and brake pedals in the car we are building, everyone will love it"
Insert frustration, car crashes, cuss words and...
6) The Google Omnibar.... lets not even talk about it.... one word: WHY????? Fill in for me what I typed yesterday??????? REALLY????????
7) Another thing about Google and in this case Andriod... Here is an example from my phone right now:
Today is Thursday July 5th at 5:11pm
My phone's call Log says I had a call: "incoming call - 2 days ago" When I click on that call the call details say the call was actually made on Sunday July 1st at 8:42pm.
So in other words the call wasn't received "2 days ago" it was received 5 days ago. The call log is wrong! Thanks Google!
This makes the call log useless for me. I have to open the call log and click on Details for every call to see when it was actually made if I want to know when a call was placed or received.
So am I upset at Google, am I upset at Andriod??? AM I upset at both?? Is the new Google Blogger interface all that bad?
Maybe... or maybe it is just me. If the user interfaces for Google products actually made sense to someone like me, an average user, then I could accept the change and improvements with all their bugs and problems...
Unfortunately this isn't the case. Google has across the board created an online environment isn't user friendly, is overly complex to use for what it does and all around "broken what didn't need to be fixed".
Blogger wasn't perfect my any means but now it is trash thanks to the Google team 'Improvements'. Honestly if Goggle had come in a simply fixed what was wrong with Blogger (a few minor tweaks) I would be right there with them cheering them on, even if there were a few bugs.
But because Google decided to change everything and in the process mess up things that used to work, change around menus that were easy to use, move simple "one click" tasks down to places I don't want to click... and gave me a phone that has a useless and messed OS... instead of making things easier, rather they have made things harder...
Because of everything they have done, I am done with Google.
A collection of comments and descriptions of the things that I am doing...
Links to stuff on this blog
Use the Site Index of Projects page link above for an easier way to find stuff on my blog that you might be looking for!
Showing posts with label Cryptography and Math. Show all posts
Showing posts with label Cryptography and Math. Show all posts
Thursday, July 5, 2012
Sunday, July 10, 2011
Conditional Formatting in Excel and Prime Numbers
By
Otto Belden
Numbers are cool and fun to play with in my opinion, especially Prime Numbers. I wrote about this some time ago in a post HERE and I've had some ideas since then. In that post I was using a Excel spread sheet with some Visual Basic code to create a number sequence then I was using another function to check if a number in a particular cell was prime. The function was scanning through a list of prime numbers in the spreadsheet and if it found a match the formatting for the cell that matches was changed to blue using Copy Formats in Excel 2007 instead of the Conditional Formatting idea. To do all that in Visual Basic for Excel was fun but overly complicated as pointed out to me by Codemann8. He commented on that last post and left a formula for Excel that can check to see if a number is prime! It's a cryptic and really cool formula that he didn't take credit for (it's out on the web) but it will check for prime numbers. I finally got around to trying this formula out and I used it to highlight prime numbers in a simple multiplication chart that uses modulo arithmetic. Below is what the Multiplication Modulo Chart looked like but I also want to show how to set this formula up to control Conditional Formatting in Excel 2007 because it took me awhile to get it to work.
![]() |
Excel 2007 Conditional Formatting in Modulo Multiplication Table |
The above picture shows what the spreadsheet ended up looking like. Along the top and down the left side are the numbers 1-257 (only 1-23 are shown) and in the middle are the products of those numbers - a multiplication chart. In the upper left corner in the highlighted cell is the modulus of multiplication. In other words the numbers in the top and left are being multiplied modulo 23 in this case. The blue cells are the prime numbers being highlighted by the formula below using the Conditional Formatting function. At the end of this post I made a short video that cycles the multiplication chart through various number sequences showing the various patterns the prime numbers make! Really Cool!!!
Below is the formula that Codemann8 left in a comment on another post I wrote and it checks to see if a number is prime returning the Excel TRUE condition if it is. If you 'Google' that formula you will get a bunch of pages that talk about it. Whoever came up with this formula had their thinking cap on!
=OR(A1=2,A1=3,ISNA(MATCH(TRUE,A1/ROW(INDIRECT("2:"&INT(SQRT(A1))))=INT(A1/ROW(INDIRECT("2:"&INT(SQRT(A1))))),0)))
Click below to read more about how to set up Conditional Formatting in Excel 2007 to use this formula and to see the boring exciting video I made of the spreadsheet cycling through various number sequences, highlighting the prime numbers as it goes!
Saturday, October 30, 2010
MS Excel Checking Bit Positions in Bytes and other stuff...
By
Otto Belden
The other day I wanted to make a chart that showed all the numbers up to 255 sorted by the number of bits that are set to 1. Why I wanted to do this I can't remember but I manged to make a chart like that in MS Excel. I also wanted to make a spreadsheet that would show me all the 1 bit differences from any 8 bit number, all the 2 bit differences, all the 3 bit differences and so on... What I'm writing about is how I went about doing that.
MS Excel pretty much sucks when it comes to dealing with binary numbers. The "=dec2bin()" doesn't work for a useful number of bits and there are no logical operators that you can use directly from Excel. Also there are no parity checking commands or functions that are built in to the spreadsheets. What I wanted to do specifically for my first chart was take a decimal number, convert it to a binary number then count the number of bits that are set to 1 in that number. After I figured out how many 1's there were in the number I wanted to put that number into a list.
For the second chart (or set of charts) that I wanted to make I needed to get a number, do a logical Exclusive Or with another number and then count the number of bits. Anyway here is a neat picture that shows what I came up with to do both of these things.
![]() |
16 Bit dec2bin() and Parity in Excel |
I wrote here about all this stuff before in another post that pretty much just explained how to do this but didn't have any examples of how to use it. This post will have some examples of how it all works.
Sunday, October 17, 2010
Number Sequences with MS Excel Visual Basic, Prime Numbers etc...
By
Otto Belden
What is this post all about? I don't really know but it was fun to do and it is what I have been doing so this is what I am writing about! After all this blog is supposed to be about the things I am doing. Enough with the fancy introductions...
I really like number sequences, or more specifically integer sequences, because to me they are interesting in some mysterious way. I don't think that I am the only person that feels this way because there is a On-Line Encyclopedia Of Integer Sequences that is full of them here OEIS. Anyway I decided to write some Visual Basic scripts in Excel and play around with them. The first thing I decided to do was make a chart that has the square number sequence (OEIS sequence A000290) going down the page in a diagonal. That is the purple values below:
This square number sequence is the square of the integers... so start with 1, 2, 3, 4,... and square those and you get (1*1) = 1, (2*2) = 4, (3*3) = 9, (4*4) = 16 etc... What enormous amounts of fun you say!? What could possibly make this any better you ask? Adding in the missing natural numbers in a way that still preserves the diagonal of squares is the first thing that comes to my mind!
Sunday, September 12, 2010
Another Cryptographic Idea (continuing a thought)
By
Otto Belden
Another idea and this one starts back with another post that I did a long time ago. It's a short one and you can find it HERE. What I was writing about back in that post relates to multiplication with a prime modulus and how the numbers you get are all the same, just in a mixed up order. For a quick example below is what I am talking about:
Back when I wrote the original post about this I didn't have time to figure out anything to do with that but now I think that I have.
As long as the multiplication table is built using multiplication mod a prime number the table will never have the same number twice in any row or any column. That doesn't happen if the table is made using a non-prime modulus. To see what I mean go to THIS site and scroll down to the cool interactive chart they have. You can select it to be a multiplication chart and change the modulus to anything you like.
The idea would be to use this to create cryptographic diffusion in blocks of data. Maybe start with something like 8 bytes of data and multiply each one by another, incrementing one of them with each multiplication. Here is a nifty and colorful picture to help explain what I am talking about. Try changing the modulus from a prime number like 11 to a non-prime like 10 and see what happens.
The above little chart is a multiplication table mod 5. The numbers in orange are the numbers that are being multiplied mod 5 and the numbers below them are the results of the multiplication. So if you look at the green 4 in the table it's obliviously the result of 2 x 2 mod 5. If you look at the green 1 right next to it , it's the result of 2 x 3 mod 5. The interesting thing (to me anyway) is that if you look at the chart it's all the same numbers just in a different order.1 2 3 41 1 2 3 42 2 4 1 33 3 1 4 24 4 3 2 1
Back when I wrote the original post about this I didn't have time to figure out anything to do with that but now I think that I have.
As long as the multiplication table is built using multiplication mod a prime number the table will never have the same number twice in any row or any column. That doesn't happen if the table is made using a non-prime modulus. To see what I mean go to THIS site and scroll down to the cool interactive chart they have. You can select it to be a multiplication chart and change the modulus to anything you like.
The idea would be to use this to create cryptographic diffusion in blocks of data. Maybe start with something like 8 bytes of data and multiply each one by another, incrementing one of them with each multiplication. Here is a nifty and colorful picture to help explain what I am talking about. Try changing the modulus from a prime number like 11 to a non-prime like 10 and see what happens.
Modular Multiplication with Rotation (shifts) |
Saturday, July 10, 2010
US Cyber Command Seal and the Secret Code (sorta)
By
Otto Belden
Recently the United States Cyber Command made the news when they announced themselves to the world and unveiled their official seal. There is a write up in Wikipedia HERE that includes a picture of the seal and a description of who they are and what they are going to do. Usually news like this isn't something that I would write about in my blog but I thought I'd make an exception in this case because many friends have been asking me about specifically the "secret code" in the Cyber Command seal.
The hexadecimal code in the seal is what really made the headlines because it immediately got people to put on their tin foil hats and start talking about government conspiracies and hidden meanings. There was even a contest offering a prize to the first person to 'decode' it all. In one of the news stories the Commander of the Cyber command said that the code was an MD5 hash of the units mission statement but he seemed a bit vague about it and didn't come right out and explain why it's there or what it's meaning might be. He even indicated that it might not be the entire mission statement but only part of it, but which part? Obviously only the nefarious world domination part of course.
Click below to read more about the Cyber Seal!
The hexadecimal code in the seal is what really made the headlines because it immediately got people to put on their tin foil hats and start talking about government conspiracies and hidden meanings. There was even a contest offering a prize to the first person to 'decode' it all. In one of the news stories the Commander of the Cyber command said that the code was an MD5 hash of the units mission statement but he seemed a bit vague about it and didn't come right out and explain why it's there or what it's meaning might be. He even indicated that it might not be the entire mission statement but only part of it, but which part? Obviously only the nefarious world domination part of course.
Click below to read more about the Cyber Seal!
Saturday, June 5, 2010
MS Excel DEC2BIN 32 bit, Rotate No Carry, Sub Table, XOR and Num 0's
By
Otto Belden
I use Microsoft Excel for just about everything all the time. Below is a list of some of the more offbeat things that I have done with it and I find useful. Some of these things I have included in other blog posts where I was writing about something else, and I found that from time to time I would go back to my own blog and look for them to copy into a spreadsheet that I was working on. It's so much easier to copy something than it is to figure it out again... Even though I wrote the blog post, and I don't have too many posts, it was a pain to find the things I was looking for. I decided to not only put them in one place for my own reference I figured I might as well explain more or less how they work in case anyone else was interested. Here you go:
Decimal To Binary Conversion With Lots of Bits in Excel: DEC2BIN
Up to 10 Bit Decimal To Binary Conversion
=DEC2BIN(G22,10)
Yeah big deal!! This is just the built in function in Excel that we all hate because it only converts up to 10 bit numbers. Anything bigger than that and you get that super fun " #NUM! " error... but wait it's worse than that! They actually only allow negative numbers to 512 and positive ones to 511 with the most significant bit being the +/- sign so you don't even get all 10 bits really... That sucks because I always find myself needing more bits than that. Below are some uses of the same DEC2BIN function to get more bits:
16 bit Decimal To Binary Conversion (a hard to read version)
=DEC2BIN(INT(G22/256),8)&DEC2BIN(MOD(G22,256),8)
The above line will give you a 16 bit number with all the bits "stuck together" of whatever 16 decimal value is in cell G22 like this:
1011010110011101
As you can see all the bits are 'stuck together'. That can be very hard to read especially when you are interested in one bit in particular - like the 9'th one from the right - and you have to count them to find it. To fix that you can change the above line to add a decimal point, a space or anything else between each group of 8 bits (each byte) in the &" "& below:
16 bit Decimal To Binary Conversion (easier to read)
=DEC2BIN(INT(G23/256),8)&" "&DEC2BIN(MOD(G23,256),8)
and the above number becomes this:
10110101 10011101
With the space in there (or anything else...) it's so much easier to read. The below examples have a decimal point in between the bytes but you can put in anything you like between the quotes &" "& and it will be between the bytes.
How does this work?? Good question! It works by doing some math to break the "big number" (bigger than 8 bits) down into 8 bit values then converting them individually and then sticking them together with the & (ampersand). That is why in the above example the first part to the left of the & is INT(G23/256) to give the upper 8 bits and the lower 8 bits being derived by the MOD(G23,256) part. If you want to see each of the 8 bits of the 16 bit value in different cells on the spreadsheet just take everything to the left of the ampersand and put it in one cell and everything to the right in another cell.
To get more bits converted its a simple matter of sticking more math conversions together with more &'s like the examples below:
24 Bit Decimal To Binary Conversion
=DEC2BIN(INT(G24/65536),8)&"."&DEC2BIN(MOD(G24/256,256),8)&"."&DEC2BIN(MOD(G24,256),8)
If you look close at the above 24 bit conversion you can see the last 2 parts separated by the &" "& is very similar to the 16 bit conversion above except a MOD has been switched into the location where the INT was. In addition the upper 8 bits of the 24 bit value is being calculated with the INT(G24/65536) part.
32 Bit Decimal To Binary Conversion
=DEC2BIN(MOD(G24/16777216,256),8)&"."&DEC2BIN(MOD(G24/65536,256),8)&"."&DEC2BIN(MOD(G24/256,256),8)&"."&DEC2BIN(MOD(G24,256),8)
The 32 bit example above HAS BEEN FIXED on July 13, 2010 and is a continuation of the same thing and by now it should be obvious how it works.
Rotate No Carry: (bit shift with a rotated bit carry)
Rotate No Carry is the geeky way to say I want to shift all the bits of my number one direction and if the bits 'fall off' the end just rotate them around to the other side. HERE is a Wikipedia entry about it if you want to know more about it.
Math is cool for so many reasons but one really cool reason is if you multiply a number by 2 mod 2^n-1 what you are really doing is a Rotate No Carry to the left one place (almost), where n is the number of bits in your number. If you multiply by 4 mod 2^n-1 you are rotating two places, multiply by 8 mod 2^n-1 is three places, 16, 32, 64 and 128 is obviously rotating more places to the left etc...
So lets say you have an 8 bit number like 01100000 and you multiply it by 8 mod 255 (which is 8 mod 2^n-1), you get 00000011. So in other words the two 1's in the first number above have rotated three places to the left and back around to the right. I said this math trick almost works because there is one case that it doesn't work and for an 8 bit number that is when the number you are rotating is 255.
The problem is if you multiply 255 by anything mod 255 you get 0. That sucks because 255 is 11111111 (all one's) so if you multiply 255 by any amount you get all 0' and not all 1's. To get around this little inconvenience I use the IF statement in Excel and say "if the number to rotate is less than 255 then rotate it, otherwise leave it at 255"
The problem is if you multiply 255 by anything mod 255 you get 0. That sucks because 255 is 11111111 (all one's) so if you multiply 255 by any amount you get all 0' and not all 1's. To get around this little inconvenience I use the IF statement in Excel and say "if the number to rotate is less than 255 then rotate it, otherwise leave it at 255"
So in the 8 Bit Rotate No Carry line below the IF statement is saying "IF(the value in A24 is less then 255) then (multiply A24 by the value in cell C18 mod 255) otherwise (it equals 255)
8 Bit Rotate No Carry
=IF(A24<255,(MOD(A24*C18,255)),255)
This line will Rotate No Carry the 8 bit value in cell A24 to the left the number of bits determined by cell C18.
One important thing to know is what value to use in the C18 position to rotate the bits the desired number of positions. I created a really confusing chart to do that and to also help count from the right or to the left depending on which direction you are trying to rotate.
Confusing Chart:
IN | IN BINARY | IN ROTATED | IN ROTATED | X BY |
2 | 00000010 | 00000100 | 4 | 2 |
2 | 00000010 | 00001000 | 8 | 4 |
2 | 00000010 | 00010000 | 16 | 8 |
2 | 00000010 | 00100000 | 32 | 16 |
2 | 00000010 | 01000000 | 64 | 32 |
2 | 00000010 | 10000000 | 128 | 64 |
2 | 00000010 | 00000001 | 1 | 128 |
2 | 00000010 | 00000010 | 2 | 256 |
What this chart is saying is start with the IN number 2 which IN BINARY is 00000010. To rotate it one position to the left X BY 2 (the rotated value is 4 by the way) . To rotate two positions to the left X BY 4; three positions to the left X BY 8 etc...
Pretty obvious I know but what if you want to rotate it to the right 6 places? It's still pretty obvious but I always find myself scribbling 1's and 0's on scratch paper and counting them. Now I have a chart to look at and so do you!
What about rotating values that are more than 8 bits you ask??
This is the exact same thing but instead of using the value of 2^8-1 (255) in the above IF statement for 8 bits you replace it with 2^16-1 (65535) for 16 bits or for 24 bits use 2^24-1 (16777215) and finally for 32 bits use 2^32-1 (4294967295). Below is what that looks like for a Rotate NO Carry of a 24 bit value:
This is the exact same thing but instead of using the value of 2^8-1 (255) in the above IF statement for 8 bits you replace it with 2^16-1 (65535) for 16 bits or for 24 bits use 2^24-1 (16777215) and finally for 32 bits use 2^32-1 (4294967295). Below is what that looks like for a Rotate NO Carry of a 24 bit value:
24 Bit Rotate No Carry
=IF(G24<16777215,(MOD(G24*4,16777215)),16777215)
Again I like confusing charts so I made another one for reference during hot and heavy bit rotation calculations where confusion can be a bit killer. The values in Red above I got out of this chart:
Function | Value | -1 |
2^8 | 256 | 255 |
2^16 | 65536 | 65535 |
2^24 | 16777216 | 16777215 |
2^32 | 4294967296 | 4294967295 |
Here is an exciting example of the 24 bit DEC2BIN and the Rotate No Carry function!
Say we start with a decimal number like 12632064 in cell G24 which in binary is:
11000000 11000000 00000000 (24 Bits)
Then we decide to Rotate with No Carry (24 bit) this number left 2 places (multiply by 4):
=IF(G24<16777215,(MOD(G24*4,16777215)),16777215)
We get: 196611 which in binary is:
00000011 00000000 00000011
You can see that it all got rotated two places to the left and the left most 2 bits got rotated around to the right most positions! Thoroughly exciting!!!
Sub Table OFFSET: (substitute)
The OFFSET function in Excel is handy if you want to substitute one number with another number. OFFSET works just like an array lookup (but the LOOKUP function in excel doesn't, so don't use that one). This is useful if you want to convert numbers from one value to another without any mathematical relationship between the two like a substitution table in a cipher. Here is an example:
=(OFFSET(D43,D40,0,1,1))
What this will do is count down cells by the value in D40 starting in cell D43 and return whatever value it finds there. For example if the value in cell D40 is 0 then you get the value of D43. If the value in cell D40 is 1 then you get the value of the cell right below D43. If the value in cell D40 is 6 then you get the value in the cell 6 cells below D43and so on...
You can also use this to do 2 dimensional array style substitutions and probably a whole lot more. Actually the OFFSET functions does all kinds of neat stuff but I won't go into everything it does because I don't use it for anything else.
Count Number of 0's: (parity)
This is handy when you have a cell with a bunch of different numbers (or characters) in it and you want to know how many of a particular number (or type of character) is in that cell. I use it for counting the number of 1's in a cell that contains a binary number. This is a useful way to find the parity of a binary number or just for counting 1's which is super fun all by itself.
The above line will count the number of 1's (or anything else you put in the blue location) and return how many of them there are. If it's a binary number it will count the number of 1's. You can couple that with something like:
The above line will tell you if there is an EVEN or an ODD parity or number of 1's (or whatever) in that cell. Endless fun for the entire family!!!
Exclusive OR XOR:
This one is a MS Excel Visual Basic Function and if you don't know how to write custom functions I suggest you figure it out. It's easy to do by going to Excel and clicking on the Developer Tab (usually far right) and then the Visual Basic tab (usually far left). A new window opens and you can click on that windows HELP button to get the Visual Basic help menu. Also Google "MS Excel Visual Basic" and there is a lot out there to explain it. IMPORTANT: You have to set Excel to a Macro-Enabled worksheet and enable macros in the security properties to get it to work. Once it does work copy the below code into the Visual Basic window and save it. When you go back into excel click on any cell and start typing =EXCLUSIVEOR and at that point the function EXCLUSIVEOR will show up (it didn't before) just like any other built in Excel function.
Function EXCLUSIVEOR(Byte1 As Long, Byte2 As Long)
'
' EXCLUSIVEOR (Byte1 , Byte2)
' XOR Exclusive Or of Two 8 bit Byte's
' June 2010 http://ottobelden.blogspot.com
'
'
' EXCLUSIVEOR (Byte1 , Byte2)
' XOR Exclusive Or of Two 8 bit Byte's
' June 2010 http://ottobelden.blogspot.com
'
EXCLUSIVEOR = Byte1 Xor Byte2
End Function
End Function
This is really handy if you are doing a lot of bit and byte things. The syntax for it is:
=EXCLUSIVEOR(C11,C12)
What you will get is the logical XOR (Exclusive Or) of the values in cells C11and C12. You can write your own functions of course and give them different names as long as they are not the same names as built in Excel functions like SUM or OFFSET or anything else. To make functions that do other logical operations change the Xor above to And or Not or something similar! Wow!!
You can even write your own Visual Basic code to do pretty much anything as long as it's an "enabled" workbook. For some examples of other code I have written check out these blog posts (scroll to the bottom of each blog post for the example code):
Linear Approximation Table for Cryptanalysis in MS Excel More Excel Fun
Those are two of many...
That pretty much is the end of everything that I wanted to write today. I may add some more to this post or I might add another post and link to it here if I think of anything else. Like I mentioned at the beginning of this post I wrote this for myself to have a place to put a few of the things I use a lot so I'll have them in one spot.
Saturday, March 6, 2010
Linear Approximation Table for Cryptanalysis in MS Excel
By
Otto Belden
This post I suppose doesn't have a real purpose other than a place to put the code that I wrote to look for linear relationships in substitution tables. This is along the same lines of the Differential Cryptanalysis post I did awhile back. Whats the point? I ask myself that often... mostly it's something to do... anyway in a cipher at some point there is something that is non linear. Most often but not always that is a look up table where one value is substituted for another one. This is basically the same idea of the decoder rings some of us had as kids where one letter in a message is changed for another one and so on until the whole message has been encrypted. Even the 'real' ciphers these days have some kind of substitution in them or some non linear equivalent. One example of a cipher with a substitution table is the Advanced Encryption Standard but there are many many others. There are many many different approaches to getting a cipher to be non linear but the table look up is a common way. Anyway... From the title of this post and what I have been writing so far you have probably guessed the goal is to make the output have a non linear relationship to the input. The reason for doing this is because if there is a linear (predictable) relationship between what goes in to what comes out you haven't really encrypted the message very well. The way this is commonly presented is in a Linear Approximation Table. Click HERE for some in depth info on this topic. What I am going to describe below is my non mathematical take on it.
Linear Cryptanalysis is a method for looking at the relationships between certain bits going into a part of a cipher and the bits coming out. Really it is asking how probable is it that I'll get a 1 or 0 on the output if I put a 1 or 0 on the input. This is usually done when looking at the substitution table in a cipher. An example of this might go something like this: (this is a goofy explanation but I think it gets the point across)
Suppose there is one byte value (8 bits) of data that goes into a look up table and some different byte value (8 bits) comes out. Also suppose that you look at the first 2 bits of that byte going in each time you send a value in there, and you send in all possible values that have the first 2 bits set to one. That would be a total of 64 byte values that you send into the table to get substituted for new values. Each time you send a value in you look at the value that comes out of the table and write it down. Once you are done you have a list of 64 numbers that came out of the table. Now maybe while looking at that list of numbers you notice that the 1st and 3rd bit of every one of the numbers in the list is a 1. You might say at this point that the first two bits of the input equal the first and third bit of the output. To put it another way you could say that those bits all have the same parity. To put it yet another way you could say that if the first and second input bits are I1 and I2 and the first and third output bits are O1 and O3 then: I1 + I2 = O1 + O3 = 0 where the + (plus sign) is binary Exclusive Or.
Another equation that also might work could be I3 + I5 + I8 = O3 + O4 = 1. The difference between these two formulas other than the bits being used is one equals 0 and the other equals 1. That's because one equation is a linear relationship and the other is affine. Affine to my nut and bolt pea sized brain is symmetry so I haven't quite figured out why those two are not exactly the same thing but for a linear approximation table that doesn't really matter. What matters is how many equations like the two above hold true with all possible combinations of input and output bits.
Finally here is the last detail of this stuff: If the table has all the possible values in it and all the values are different (no numbers repeat) and non linear then any given equation we pick will hold true half the time. In the case of a table from 0 to 255 values (or a total of 256 values) exactly half is 128. To stick with the way the professionals do this sort of thing I'll subtract 128 from the total number of occurances so that we will be counting from -128 to +128 with 0 right in the middle. That way a 0 in the output from the code I'll eventually get around to writing about in this post will indicate a non linear combinations of bits in the equation. A more negative value will indicate a affine relationship and a positive number a linear one. The more 0's you have in the output and the closer any numbers are to 0 the more non linear the table is.
OK that's really fun! Are you still awake after reading all this?? If an equation like the one above holds true most of the time for a substitution table then the table isn't doing a very good job of being non linear. In fact by knowing a few of the output bits you have a pretty good idea of what the input is, or at least you can narrow it down. What you would expect to see if the table is non linear or random is the equation like the one above would be correct half of the time and only half the time. So the goal of this is to look at combinations of input bits and compare them to combinations of the output bits looking for combinations that are 'correct' more than half the time. Once we have found input to output combinations that are more likely than others we can predict how the substitution table is doing it's thing.
So having said all that let me summarize by saying that to do this a person needs to choose all combinations of input bits and compare them to all the combinations of output bits with every possible input to the table. Doing this by hand would take a really long time so I wrote some Visual Basic scripts that run in Excel to do it for me. Computers are real time savers!
I ran into a couple of interesting programming issues when trying to do this. One is a really annoying trait of Visual Basic that allows you to misspell a variable name in a program and it won't give you an error. In fact it runs along just fine treating the misspelled variable as a brand new variable. In fact I beat my head against the wall trying to figure out why the code didn't give the expected results until I noticed I had misspelled a name in the code... Computers are real time savers!
The other issue that I had a problem with is figuring out how to exclusive or together only a few bits in a byte at a time. What I decided to do it pre-compute the exclusive or of all the bits ahead of time and put them in the Excel sheet. I did this by creating a column of all the numbers from 0 to 255 then right next to it converting them to binary with the Excel formula:
=DEC2BIN(A23,8)
That converts the numbers from decimal to 8 bits of binary ones and zeros. Then I used this formula:
=LEN(G5)-LEN(SUBSTITUTE(G5,"1",""))
to count the numbers of ones in each 8 bit value. After I did that I took the number of 1's and reduced it mod 2 with:
=MOD(A23,2)
which then gave a value of 0 if the number of 1's was even and a 1 if the number of 1's was odd. That is the same as Exclusive Or'ing all the 1's together.
Isn't that fun!! Wow OK!! Once I had the column of 1's and 0's that was equal to the parity of each value from 0 to 255 all I had to do was select every combination of input and output bits and with every combination run through all input values from 0 to 255. Check out the code at the bottom of the post, there are three Visual Basic Functions to look at. One sends to the worksheet the maximum Linear approximation occurrences value (either + or negative with no sign), the input and output bit combinations that created it (one of possibly many combinations) and the number of 0's in the table. The other piece of code prints out the entire Linear Approximation Table table to the screen with the output bit combinations across the top and the input combinations down the side. Be warned this is a big table and it takes about 10 minutes to make it. The last piece of code runs through a table looking for differential cryptanalysis relationships similar to my other post but without the table output.
To test these pieces of code I ran them on a couple of substitution tables that I knew the answers to. One was the Advanced Encryption Standard substitution table and another table I got off the internet in a theoretical paper.
AES Sub Table has max linear approximation value of 16 and a difference distribution value of 4. The other table that I got off the internet that was proposed as a substitution table has a max linear table value of 22 and a max difference distribution table value of 6.
In anyone actually reads all this and notices any errors please let me know!
//******************
Excel Visual Basic Code:
Linear Approximation Values Code
This code needs the "Parity Chart" column starting in cell B6 and will print out the max parity value (unsigned) the Input and Output masks that created that parity value - there may be others but at least one set and also print out the number of 0 or non-linear values. The substitution table being investigated should start at cell C6.
Sub LinearList()
' This code will run thru all possible
' input and output bit combinations (masks)
' checking them against all inputs, keeping
' track of the highest + and - parity masks
' then print out which masks produced the
' greatest number of parities
' http://ottobelden.blogspot.com
' Locate stuff on the sheet
Dim ParChart As Byte ' Parity Chart Top
Dim SubTab As Byte ' Sub Table Top
SubTab = 6 ' Sub Table row 6
ParChart = 6 ' Parity chart row 6
Dim IMasked As Integer ' Mask Values
Dim OMasked As Integer
Dim ParMax As Integer ' keep track of Max Parity
Dim IMaskMax As Integer ' Max input mask
Dim OMaskMax As Integer ' Max output mask
Dim Zeros As Long ' how many zero entries
Dim Temp As Integer ' temp value of parity
Cells(2, 3) = Time
Application.ScreenUpdating = False
For Imask = 1 To 255 ' Input Mask
For Omask = 1 To 255 ' Output Mask
For Input1 = 0 To 255 ' Input Value
IMasked = Input1 And Imask
IMasked = Cells(IMasked + ParChart, 2)
OMasked = Cells(Input1 + SubTab, 3)
OMasked = OMasked And Omask
OMasked = Cells(OMasked + ParChart, 2)
If OMasked = IMasked Then
Temp = Temp + 1
End If
Next Input1
'
Temp = Abs(Temp - 128)
If Temp = 0 Then
Zeros = Zeros + 1
End If
If Temp > ParMax Then
ParMax = Temp
IMaskMax = Imask
OMaskMax = Omask
End If
Temp = 0
Next Omask
Next Imask
Application.ScreenUpdating = True
' Print out data
Cells(3, 3) = Time
Cells(5, 6) = ParMax
Cells(6, 6) = IMaskMax
Cells(7, 6) = OMaskMax
Cells(8, 6) = Zeros
End Sub
' This code will run thru all possible
' input and output bit combinations (masks)
' checking them against all inputs, keeping
' track of the highest + and - parity masks
' then print out which masks produced the
' greatest number of parities
' http://ottobelden.blogspot.com
' Locate stuff on the sheet
Dim ParChart As Byte ' Parity Chart Top
Dim SubTab As Byte ' Sub Table Top
SubTab = 6 ' Sub Table row 6
ParChart = 6 ' Parity chart row 6
Dim IMasked As Integer ' Mask Values
Dim OMasked As Integer
Dim ParMax As Integer ' keep track of Max Parity
Dim IMaskMax As Integer ' Max input mask
Dim OMaskMax As Integer ' Max output mask
Dim Zeros As Long ' how many zero entries
Dim Temp As Integer ' temp value of parity
Cells(2, 3) = Time
Application.ScreenUpdating = False
For Imask = 1 To 255 ' Input Mask
For Omask = 1 To 255 ' Output Mask
For Input1 = 0 To 255 ' Input Value
IMasked = Input1 And Imask
IMasked = Cells(IMasked + ParChart, 2)
OMasked = Cells(Input1 + SubTab, 3)
OMasked = OMasked And Omask
OMasked = Cells(OMasked + ParChart, 2)
If OMasked = IMasked Then
Temp = Temp + 1
End If
Next Input1
'
Temp = Abs(Temp - 128)
If Temp = 0 Then
Zeros = Zeros + 1
End If
If Temp > ParMax Then
ParMax = Temp
IMaskMax = Imask
OMaskMax = Omask
End If
Temp = 0
Next Omask
Next Imask
Application.ScreenUpdating = True
' Print out data
Cells(3, 3) = Time
Cells(5, 6) = ParMax
Cells(6, 6) = IMaskMax
Cells(7, 6) = OMaskMax
Cells(8, 6) = Zeros
End Sub
Linear Approximation Table Code
This code needs the "Parity Chart" column starting in cell B6 and will print out the entire table. The substitution table being investigated should start at cell C6.
Sub Linear()
' This code will create a Linear Approximation Table
' of a 256 byte substitution table in a column
' starting at cell SubTab
' Set up 3 loops, one for an input mask, second output
' mask and one to loop thru all 256 inputs
' An additional table column at cell ParChart is
' the parity of each value from 0 to 255
' http://ottobelden.blogspot.com
'
'These values locate stuff on the Excel sheet
Dim ParChart As Byte ' Parity Chart Top
Dim SubTab As Byte ' Sub Table Top
Dim ChartOut As Byte ' Output chart column
Dim ChartIn As Byte ' Output Chart Row
ChartOut = 5 ' Chart column E = 5
ChartIn = 6 ' Chart row = 6
ParChart = 6 ' Parity chart row 6
SubTab = 6 ' Sub Table row 6
Dim IMasked As Long ' input bits masked
Dim OMasked As Long ' output bits masked
Application.ScreenUpdating = False
Cells(2, 3) = Time
For Imask = 0 To 255 ' Input Mask
For Omask = 0 To 255 ' Output Mask
For Input1 = 0 To 255 ' Input Value
IMasked = Input1 And Imask
IMasked = Cells(IMasked + ParChart, 2)
OMasked = Cells(Input1 + SubTab, 3)
OMasked = OMasked And Omask
OMasked = Cells(OMasked + ParChart, 2)
If IMasked = OMasked Then
Cells(ChartIn + Imask, ChartOut + Omask) = Cells(ChartIn + Imask, ChartOut + Omask) + 1
End If
Next Input1
Cells(ChartIn + Imask, ChartOut + Omask) = Cells(ChartIn + Imask, ChartOut + Omask) - 128
Next Omask
Next Imask
Application.ScreenUpdating = True
Cells(3, 3) = Time
End Sub
' This code will create a Linear Approximation Table
' of a 256 byte substitution table in a column
' starting at cell SubTab
' Set up 3 loops, one for an input mask, second output
' mask and one to loop thru all 256 inputs
' An additional table column at cell ParChart is
' the parity of each value from 0 to 255
' http://ottobelden.blogspot.com
'
'These values locate stuff on the Excel sheet
Dim ParChart As Byte ' Parity Chart Top
Dim SubTab As Byte ' Sub Table Top
Dim ChartOut As Byte ' Output chart column
Dim ChartIn As Byte ' Output Chart Row
ChartOut = 5 ' Chart column E = 5
ChartIn = 6 ' Chart row = 6
ParChart = 6 ' Parity chart row 6
SubTab = 6 ' Sub Table row 6
Dim IMasked As Long ' input bits masked
Dim OMasked As Long ' output bits masked
Application.ScreenUpdating = False
Cells(2, 3) = Time
For Imask = 0 To 255 ' Input Mask
For Omask = 0 To 255 ' Output Mask
For Input1 = 0 To 255 ' Input Value
IMasked = Input1 And Imask
IMasked = Cells(IMasked + ParChart, 2)
OMasked = Cells(Input1 + SubTab, 3)
OMasked = OMasked And Omask
OMasked = Cells(OMasked + ParChart, 2)
If IMasked = OMasked Then
Cells(ChartIn + Imask, ChartOut + Omask) = Cells(ChartIn + Imask, ChartOut + Omask) + 1
End If
Next Input1
Cells(ChartIn + Imask, ChartOut + Omask) = Cells(ChartIn + Imask, ChartOut + Omask) - 128
Next Omask
Next Imask
Application.ScreenUpdating = True
Cells(3, 3) = Time
End Sub
Difference Distribution Table Max Value Code
Sub DList()
' This code will create an array
' corresponding to the Xor or 2 inputs
' (indif) then index into the array a value
' that is the Xor of the sub of each
' input, incrementing the array value
' then find the max value of the array
' http://ottobelden.blogspot.com
Dim Outs(256) As Integer
Dim Temp As Integer
Dim MaxVal As Integer
Dim Input2 As Integer
Cells(2, 3) = Time
Application.ScreenUpdating = False
For Indif = 1 To 255
For Input1 = 0 To 255 ' Loop thru input values
Input2 = Input1 Xor Indif
Temp = Cells(Input1 + 6, 1) Xor Cells(Input2 + 6, 1)
Outs(Temp) = Outs(Temp) + 1
Next Input1
' Find max value in array
For Check = 0 To 255
If Outs(Check) > MaxVal Then
MaxVal = Outs(Check)
End If
Next Check
Erase Outs
Next Indif
Application.ScreenUpdating = True
Cells(3, 3) = Time
Cells(4, 4) = MaxVal
End Sub
Saturday, February 20, 2010
Multiplication (more about nothing)
By
Otto Belden
I think that I mentioned in another post that I have been playing around with multiplication tables. They make neat pictures and really handsome tablecloth patterns as well as matching place mats. The below picture is a multiplication table mod 257 that I made in Excel. Cool pattern if you click on it to enlarge it and look at it...
The really interesting - not that they make cool place mats but that the numbers all end up being what they are (cool if you are a geek). When you make a multiplication table like this using a modulus that is prime the rows of the table (or columns) end up being permutations of all the possible numbers in the field (modulus - 1). Below is a multiplication table mod 5 without the 0's row / column because those are all 0's obviously.
1 2 3 4
1 1 2 3 4
2 2 4 1 3
3 3 1 4 2
4 4 3 2 1
I'll write more about this later if I feel like it.
HERE is a link to more about this stuff with a fun table that you can put in your own modulus and choose which operator you are interested in (+ - X /). HERE is a link to the home page for that link that has a lot of interesting math related puzzles and other fun stuff.
Anyway that is about it... more later.
Sunday, January 31, 2010
Tables of various kinds... Stripping Table and a Substitution Table
By
Otto Belden
This week I would like to write about a couple of tables, the kind I am stripping paint off of and substitution tables... I'll start by giving a short update on the paint stripping going on with serious Klean-Strip KS-3 Premium Stripper action. To give you a quick visual reminder of what I am doing check out This Recent Picture of the table and also This One (click on the links!). Anyway the weather has cleared up a bit so I was able to do the paint stripping in the back of the house instead of in the front where I had some shielding from the rain. As you might be able to see in the below picture one side of the table has had the paint stripped off (right side) and the other side still has some ugly pink paint. That didn't last long as two coats of the paint stripper got most of the paint and primer off the left side.
In my estimation I should do at least one more coat of the stripper over all the tough spots to get what remains of the primer and little bits of paint off. Then I'll have to start on the sanding... not going to be fun on all the curved surfaces but promises to be a richly rewarding penultimate step in coating removal.
Moving right along at a feverish pace I'd like to write a bit about substitution tables and diffusion. Yes I know this is boring to most of my faithful readers, not being at all as exciting is stripping paint of tables (wait 'till I write about paint drying!) but substitution tables and cryptographic confusion interest me. Again to start off with some quick reminders of what in the world I am writing about HERE is a link to my last post somewhat related to this topic. Kinda also related to this is a Wikipedia entry about this as well (click HERE for that if interested).
Substitution tables are just lookup tables that are used to substitute one input value for another different value. As I wrote about in the Difference Distribution Table post that I linked to above and tricked you into clicking on again here there are some important structures to consider when designing a substitution table. The obvious idea would be to fill the table up with random numbers, when you index in you get a random number out! This is great until you use the same table over and over again. Patterns in the input to the table will give you patterns in the random numbers you get out of the table because if the most common input number is 6 for example, and 6 gets substituted for 11 then the most common output will be 11. Anyway that is one issue with the tables in addition to what I wrote about in THIS post. OK if you clicked on that last link it again took you to the same page - I just thought it would be funny to link to the same page three times! Ha Ha! I promise not to do that anymore. To summarize... usually in a substitution table you index into the table based on the value you are going to substitute and get whatever value is in the table at that location. If the input is 1 you grab the first value, if the input is 34 you grab the 34th value etc... if you have a string of 34's as the inputs then you get a string of whatever the 34th value is as the outputs.
Anyway I have been thinking about and tinkering around with this idea of using one or maybe two substitution tables and indexing into them based on the input data. This idea incorporates the Sawtooth idea that I wrote about some time ago in that it 'moves across' the input data from left to right then back through the changed input data right to left. I have not done too many tests in Excel on this one nor have I written any fancy Visual Basic code to play with it. I did do a spreadsheet to play around with it a bit though... here is the basic idea:
Take a few byte sized input values, lets say 4 of them called inputs A, B, C, and D. Just for fun and to keep it simple say the values for these are 2, 3, 4 and 5 in order. Now have a substitution table handy that has 256 numbers in it from 0 to 255 all mixed up in a random order with no numbers repeating. For what I am thinking here the order doesn't really matter but having all the numbers different ant not in order is important.
OK now index into the table the first value A or 2 in this case. Whatever the 2nd number in the table is that is the new value of A. Now get the second number which is 3 and instead of indexing into the table to the third place - index in to the 5th value - that 5th value is the new value of B. Why the 5th value? Because the first value of A was 2 and three more into the table is 5. The next value is 4 so go into the table 4 more places and you are at the 9th value - that is the new value for C. The last input number is 5 so go in 5 more places starting from the 9th place and you get the 14th value as the new value for D.
At this point you have four new values for A, B, C and D and each new value depends on the previous values. If you were to do this again but change the value of B, this time the value for B would be different but so would the values for C and D because of the additive way that you index into the table. So changing the value of one number would change the values of all the numbers that come after it.
That was so much fun lets do it again! But this time to mix it up a bit lets go in reverse order and lets ExclusiveOr the numbers instead of just substituting them. Here we go: Take the new value for D that we got above and index into the table that many locations (whatever D is) and ExclusiveOr whatever number is in that location with the value of D. Now add the value of C from above to whatever D was and go that far into the table and ExclusiveOr that value with whatever C was. Do it again for B and A.
OK so now at this point because we went and substituted A, B, C, and D, adding in the values to index the first time and then with the new values we went in reverse order all the values now depend on all the other values. Another way to look at this is (as I mentioned above) changing B would change C and D when we go back in reverse order that changed B value would now change the value of A. So after having done this forward additive indexing and reverse additive indexing into the substitution table all the new values would depend on all the input values. Changing any one of the input numbers would tend to change all the output numbers.
Let me anticipate your next question - why Exclusive Or the second time through? I was wondering this myself and I think I have 2 answers to that question. The first one is the way addition works. For a second lets pretend that we don't do the ExclusiveOr. Lets also say in the second indexing operation you have the first two values of 4 and 6. These index into the table to the 10th location so the output is the 10th number. Now lets pretend some more and imagine that the first two numbers have changed to 8 and 2. Those now also index into the 10th location. So the first two numbers have changed but the third number is still the 10th value from the table. This is undesirable.
Now do the same thing we just did but with the ExclusiveOr. This time the numbers of 4 and 6 get us to the 10th value which we ExclusiveOr with 6 to get some number. The next time we have the values of 2 and 8 that also get us to the 10th number but this time we ExclusiveOr with 8 and get some different number than we got the first time. Pretty cool... now the second reason I happen to have forgottan but off the top of my head I would guess that I was thinking that ExclusiveOr'ing with the table value instead of just substituting it makes it harder to work backwords.... if you knew the 4 output values of the table with the ExclusiveOr it would be harder to go back and figure out what the input values were.
Anyway that is about all I want to write about tables today. I'm pretty sure that the paint stripping and table base will work when I finally finish it but I'm not sure about my substitution table idea... more on that later!!!
Monday, January 11, 2010
Difference Distribution Table (DDT) in Excel...
By
Otto Belden
It has been a few days since I have had time to post anything here on my Blog, not because I have not been doing things but I have just been busy with the holidays and the New Year... But now that I have a few spare moments I'd like to write about some more fun Excel programming that I have been doing!!!
In the exciting world of cryptography there is a concept called Differential Cryptanalysis. If you click on the link it will take you to a Wikipedia explanation of what it is. My uneducated explanation of how it works goes something like this: If you have 2 different inputs to a cipher they will give you 2 different outputs. This holds true for either the entire cipher or just part of it and for this explanation the cipher key is the same for each input.
What someone can do is look at the differences between several inputs to a cipher and at the same time look for common output differences for each. If you see that a certain input difference frequently causes a certain output difference you have some information about how the cipher is working for that particular key. The trick when looking at input differences that make certain output differences is how likely those differences are. So really what you are doing is looking for certain differences in the outputs of a cipher that are very likely caused by certain input differences. Once you have found those you can make an educated guess about either what the input is or what key might have been used to encrypt everything. This type of attack usually doesn't give you the actual key or the actual input but it allows you to narrow down what the most likely key or input might be.
Usually when looking at a cipher in this way you would break the cipher down into small pieces and look for how differences propagate through various parts of the cipher. Most often what is looked at is the substitution tables of a cipher and that is what this blog post is about!!! I know I'm rambling a bit here...
Usually when looking at a cipher in this way you would break the cipher down into small pieces and look for how differences propagate through various parts of the cipher. Most often what is looked at is the substitution tables of a cipher and that is what this blog post is about!!! I know I'm rambling a bit here...
(Click on the pic for a better view)
A Difference Distribution Table is a chart of how often input differences make output differences for a part of a cipher - in this case a substitution table. These tables are also good for wallpaper as they tend to go on and on and on... (kinda like my blog posts) For my Excel DDT I have used one byte values for the inputs and one byte values for the outputs.
Here is how the chart above works: Along the top of the chart are columns numbered 0 to 255 representing all the output differences. Down the left hand side of the chart are similar numbers from 0 to 255 representing all the input differences.
The first step is to pick a couple of different inputs, lets say that they are 4 decimal (100 binary) and 2 decimal (010 binary). Once you have picked a couple of inputs you figure out the difference between them by exclusive or-ing them together.The binary difference (Exclusive Or) between 4 and 2 is:
100 = 4
010 = 2
110 = 6
So the input difference is 6 in this case, note that value for later.
The next step is to figure out what each of those inputs gets 'changed to' when you encipher them. In this case the change is a substitution based on a lookup table. Lets pretend that the value of 4 gets substituted to 28 and a value of 2 gets substituted to 34. If you Exclusive Or 28 and 34 you get 62. Note that value for later.
Now you have the two difference values that you need. The input difference in this case is 6 and the corresponding output differences in this case is 62. All you need to do now is go down the left hand side of the chart to row 6 (input difference) and across the top of the chart to column 62 (output difference) and add 1 to whatever value is there. Once you have done that go through every possible combination of input differences and figure out the output difference for each, updating the values in the chart. The chart at that point contains entries of the number of times each difference pair has occurred (how often in other words you get an input to output difference)
Once the chart has been filled up with all the values based on all possible inputs it's ready to use!!! Yeah! How is this chart used? One might look for really large or possibly really small values in the chart. In keeping with the example above lets say that a whole bunch of input combinations whose difference is 6 ended up making a whole bunch of output differences of 62. If that were to happen the Difference Distribution Chart would have a large value in row 6 column 62. That would mean that while the cipher is doing it's thing there is a greater than even change that the output would be 62 because so many different input pairs make that difference. In short you want the values in the chart to be very close to the same... no really big or small numbers.
Anyway that is an update on what I have been doing. Please excuse my haphazard writing style... below is the Excel Visual Basic code I wrote to create the above chart. The substitution table that I used is one I got off the internet...
Enjoy!!!!
Anyway that is an update on what I have been doing. Please excuse my haphazard writing style... below is the Excel Visual Basic code I wrote to create the above chart. The substitution table that I used is one I got off the internet...
Enjoy!!!!
Microsoft Excel VB Code for Byte Sized Difference Distribution Table
Sub DDT()
Dim OffS As Byte ' Vertical offset to Sub Table
Dim OffI As Byte ' Vert chart Offset (Row)
Dim OffO As Byte ' Horiz chart Offset (Column)
SubCol = 2 ' Sub Table is at Column 2(=B)
OffS = 10 ' Sub Table Starts at Row 10
OffI = 10 ' Chart starts at Row 10
OffO = 5 ' Chart Starts at Column 5 (=E)
Dim OutputV As Long ' Xor'd value of sub'd inputs
Dim OutA As Long ' One Sub'd value
Dim OutB As Long ' Other Sub'd Byte
Cells(4, 2) = Time
For Input1 = 0 To 255
' Index into Table = OutA
OutA = Cells((OffS + Input1), SubCol)
For Input2 = 0 To 255
' Index into Table = OutB
OutB = Cells((OffS + Input2), SubCol)
' Input V = Xor of Input's + Chart Offset Vert
OutputV = (OutA Xor OutB) + OffO
' Index into chart and increment value
Cells(InputV, OutputV) = Cells(InputV, OutputV) + 1
Next Input2
Next Input1
Cells(5, 2) = Time
End Sub
' This Macro will index into a column of values in
' the sheet that are substitutions (sub table)
' running thru all combinations of substitutions
' Xor'ing the values indexed and the sub'd values
' plotting them into a (big) frequency DDT.
' January 2010 http://ottobelden.blogspot.com
'
'These constants locate stuff on the sheet
Dim SubCol As Byte ' Column where Sub Table isDim OffS As Byte ' Vertical offset to Sub Table
Dim OffI As Byte ' Vert chart Offset (Row)
Dim OffO As Byte ' Horiz chart Offset (Column)
SubCol = 2 ' Sub Table is at Column 2(=B)
OffS = 10 ' Sub Table Starts at Row 10
OffI = 10 ' Chart starts at Row 10
OffO = 5 ' Chart Starts at Column 5 (=E)
'
'These variables are for calculations
Dim InputV As Long ' Xor'd value of 2 inputsDim OutputV As Long ' Xor'd value of sub'd inputs
Dim OutA As Long ' One Sub'd value
Dim OutB As Long ' Other Sub'd Byte
'
' Turn screen updating off and note start time
Application.ScreenUpdating = FalseCells(4, 2) = Time
For Input1 = 0 To 255
' Index into Table = OutA
OutA = Cells((OffS + Input1), SubCol)
For Input2 = 0 To 255
' Index into Table = OutB
OutB = Cells((OffS + Input2), SubCol)
' Input V = Xor of Input's + Chart Offset Vert
' OutputV = Xor of sub'd values + Chart offset Horiz
InputV = (Input1 Xor Input2) + OffIOutputV = (OutA Xor OutB) + OffO
' Index into chart and increment value
Cells(InputV, OutputV) = Cells(InputV, OutputV) + 1
Next Input2
Next Input1
' Turn screen updating on and note end time
Application.ScreenUpdating = TrueCells(5, 2) = Time
End Sub
Sunday, December 13, 2009
More Excel Fun (nothin better on a rainy day)
By
Otto Belden
Continuing in the pursuit of things I'm not very good at or understand very well, I decided to mess around a bit more with Excel and the Diffusion "thing" that I have been thinking and writing about. I got a bit bored with the 'Sawtooth' idea and decided to play with the Pseudo-Hadamard Transform. Specifically I decided to see how it works on 32 bit words or 4 bytes at a time. It's an easy thing to do with 16 bits or two bytes but 4 bytes isn't as straight forward in Excel. So to do this I wrote another Visual Basic script in Excel that will take the values in 4 cells (each a byte) then combine them into two 16 bit values. It then does the math Mod 2^16 and parses the values out into 4 new cells (each a byte). The code accepts 5 values from Excel, the first 4 are the byte values to do the calculation with and the 5th value is to determine which of the 4 output bytes to return. I posted the code at the end of this post.
What I noticed once I had done this is how crappy it seems to be at mixing or diffusing the changes in the values when you are looking at one byte at a time. I shouldn't say crappy because I probably wrote the code wrong and I'm not doing the math correctly!! Ha Ha! Anyway what I got was a function that seems to work when I check the math by hand. Below is a few examples of what happens when you change various Input Values and how the Output Values change.
The interesting thing is that if you change one value in the input, two values change in the outputs. You can change the values of the inputs to whatever you want but almost always each input changes just the values in the locations above. For example looking at the first chart above with the value of 1 in the left input row it is changing the values in the locations noted by the 2 and the 1 in the output row below it. In the second chart the value of 2 in the input row is changing the values in the locations marked with the 4 and the 2. In fact I created a spreadsheet that runs through all the input values and for every input value the changes follow the above charts with the exception below:
So looking at the two above charts the value of 128 in the second input byte from the left is changing different output values than it did in the first set of charts. When the second input value from the left goes to 129 and above it is back to changing the second and fourth output values from the left. (but it leaves the first output byte larger by 1 from then on). Wow!! This is exciting!
I suppose another way to look at what is going on here is this:
So the input in each location noted with a letter is having an effect on the output that has the same letter. Assuming you ignore the oddball change when the second input from the left is 128 and it changes the first output from the left by 1.
One problem in my opinion with doing this is only one input value is changing two of the output values. Ideally I would like to have all the output values change if one of the input values has changed. Thinking about this I decided to make two transforms in parallel with each acting on the input bytes rotated by location to the left one place. Here is a similar chart showing that:
Notice that the locations of A, B, C and D are all shifted. So imagine you have 4 input values A, B, C and D. They are 'loaded' into the chart locations above and simultaneously calculated causing the outputs to change in each location. Then the outputs from both transforms are Exclusive Or'd together to get the 4 output byte values:
Or something like that anyway. The reason I bring it up is because I did just that in a spreadsheet ;) So anyway it's not very interesting if you just take the exact same values for A, B, C, and D and put them into the same transforms and exclusive or the outputs together. What I decided to do is take the values A,B,C and D and put them into the first transform then take those values and swap the upper and lower bits (Nibble Swap). That way the the inputs to the two transforms are different but related to each other. If A changes then it's "Nibble Swapped" value will change too. An example is the value 12 decimal which = 1100 in Binary. If you look at 12 in 8 bit binary (with the nibbles separated for clarity) it's 0000 1100. If you swap the nibbles it becomes 1100 0000 which = 192 decimal.
What I noticed once I had done this is how crappy it seems to be at mixing or diffusing the changes in the values when you are looking at one byte at a time. I shouldn't say crappy because I probably wrote the code wrong and I'm not doing the math correctly!! Ha Ha! Anyway what I got was a function that seems to work when I check the math by hand. Below is a few examples of what happens when you change various Input Values and how the Output Values change.
INPUT | 1 | 0 | 0 | 0 | |
OUTPUT | 2 | 0 | 1 | 0 |
INPUT | 0 | 2 | 0 | 0 | |
OUTPUT | 0 | 4 | 0 | 2 |
INPUT | 0 | 0 | 3 | 0 | |
OUTPUT | 3 | 0 | 3 | 0 |
INPUT | 0 | 0 | 0 | 4 | |
OUTPUT | 0 | 4 | 0 | 4 |
The interesting thing is that if you change one value in the input, two values change in the outputs. You can change the values of the inputs to whatever you want but almost always each input changes just the values in the locations above. For example looking at the first chart above with the value of 1 in the left input row it is changing the values in the locations noted by the 2 and the 1 in the output row below it. In the second chart the value of 2 in the input row is changing the values in the locations marked with the 4 and the 2. In fact I created a spreadsheet that runs through all the input values and for every input value the changes follow the above charts with the exception below:
INPUT | 0 | 128 | 0 | 0 | |
OUTPUT | 1 | 0 | 0 | 128 |
INPUT | 0 | 129 | 0 | 0 | |
OUTPUT | 1 | 2 | 0 | 129 |
So looking at the two above charts the value of 128 in the second input byte from the left is changing different output values than it did in the first set of charts. When the second input value from the left goes to 129 and above it is back to changing the second and fourth output values from the left. (but it leaves the first output byte larger by 1 from then on). Wow!! This is exciting!
I suppose another way to look at what is going on here is this:
INPUT | A | B | C | D | |
OUTPUT | (A|C) | (D|B) | (A|C) | (D|B) |
So the input in each location noted with a letter is having an effect on the output that has the same letter. Assuming you ignore the oddball change when the second input from the left is 128 and it changes the first output from the left by 1.
One problem in my opinion with doing this is only one input value is changing two of the output values. Ideally I would like to have all the output values change if one of the input values has changed. Thinking about this I decided to make two transforms in parallel with each acting on the input bytes rotated by location to the left one place. Here is a similar chart showing that:
INPUT | B | C | D | A | |
OUTPUT | (B|D) | (C|A) | (B|D) | (A|C) |
Notice that the locations of A, B, C and D are all shifted. So imagine you have 4 input values A, B, C and D. They are 'loaded' into the chart locations above and simultaneously calculated causing the outputs to change in each location. Then the outputs from both transforms are Exclusive Or'd together to get the 4 output byte values:
OUTPUT | (A|C) | (D|B) | (A|C) | (D|B) |
OUTPUT | (B|D) | (C|A) | (B|D) | (A|C) |
XOR | (ABCD) | (ABCD) | (ABCD) | (ABCD) |
Or something like that anyway. The reason I bring it up is because I did just that in a spreadsheet ;) So anyway it's not very interesting if you just take the exact same values for A, B, C, and D and put them into the same transforms and exclusive or the outputs together. What I decided to do is take the values A,B,C and D and put them into the first transform then take those values and swap the upper and lower bits (Nibble Swap). That way the the inputs to the two transforms are different but related to each other. If A changes then it's "Nibble Swapped" value will change too. An example is the value 12 decimal which = 1100 in Binary. If you look at 12 in 8 bit binary (with the nibbles separated for clarity) it's 0000 1100. If you swap the nibbles it becomes 1100 0000 which = 192 decimal.
One obvious thing to mention is some values don't change when you swap the nibbles.
Obviously 0 = 0000 0000 and 255 = 1111 1111 don't change when you swap the nibbles. Neither does 17 = 0001 0001 or 85 = 0101 0101. In fact anything that is a multiple of 17 doesn't change when you swap the nibbles so I decided to fix that by performing a logical NOT (inversion) on all the values that don't change when you swap them. So 0 becomes 255, 255 becomes 0, 17 becomes 238 and 85 becomes 170. Wow!! This is exciting!! I posted the code for doing this special Nibble Swap at the end of this post.
Anyway that is what I have been up to this rainy weekend. I have not done a whole lot of testing on the above idea to see if it really does mix up the data and 'diffuse' it over the entire 4 byte output. I did write some simple scripts to run through a few thousand input values and checked for output changes and it seems to work pretty good.
On interesting thing to note about this is that the two transforms could actually be done in parallel if this were to be implemented in some kind of real time encryption system. I suppose that one method would be to take the 4 input values and substitute them with two different substitution (look-up) tables. This would be a lot better than using the Nibble Swap to get a different value for the second transform. So the A value could be substituted in two tables for 2 new values with each new value going into a transform - one being position rotated to the left. That way the values are different but would change if the A byte value changed. The subject of cryptographic substitution tables is best left for another day.
Visual Basic Code for Pseudo-Hadamard Transform (32 bit word)
Function PHT(A As Long, B As Long, C As Long, D As Long, Place As Long)
' Pseudo Hadamard Transform 16 bit words
' Shift A <<8 and C <<8 then Or C and D with them
' create Temp to hold left value
' check Place to figure out which byte is req'd as output
' December 2009 http://ottobelden.blogspot.com
Dim Left As Long
Dim Temp As Long
Dim Right As Long
Left = (A * 256) Or B
Right = (C * 256) Or D
Temp = Left
Left = (2 * Left) + Right Mod 65536
Right = Temp + Right Mod 65536
If Place = 1 Then
Left = Int(Left And 65280) / 256
PHT = Left
End If
If Place = 2 Then
Left = Left And 255
PHT = Left
End If
If Place = 3 Then
Right = Int(Right And 65280) / 256
PHT = Right
End If
If Place = 4 Then
Right = Right And 255
PHT = Right
End If
End Function
Nibble Swap with logical Not
Function SHIFTD(Value As Byte)
' Swap upper nibble for lower
' if swapping doesn't change value
' then invert (NOT) value
' December 2009 http://ottobelden.blogspot.com
Dim LN As Byte
Dim RN As Byte
RN = Int(Value / 16)
LN = (Value And 15) * 16
If Value = (LN Or RN) Then
Value = Not (LN Or RN)
SHIFTD = Value
Else
SHIFTD = LN Or RN
End If
End Function
Subscribe to:
Posts (Atom)