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!

Sunday, March 28, 2010

Time to Update the Clock and Template

This has been another busy week for me with the 2 jobs and all the other things that I have been doing but I have had a bit of time to work on the alarm clock repackaging that I mentioned last week. Also astute readers may have noticed that I also updated the template for my blog...

Clock: As I mentioned HERE I have this alarm clock that had switches that were really hard to actuate. I decided to take it apart and put all the components in a new 'case' adding easy to switch switches and other things that I think would be neat in a clock (things I have laying around). I decided to build a wood box for the clock and I started with the base from the Fruit Bowl Mirror that I made a couple of weeks ago. You can see the wood parts in the fist couple of pictures HERE. I used the center square piece that has the round stain on it as the base for the clock. It is about the right size 7" X 7" and has all the holes drilled around it's perimeter. I'm not sure how the holes will fit into the design but they might be nead places to put LED's or something... not sure yet.
Anyway Otto Jr. sanded all the nasty plastic wood varnish off the wood for me while I cut some pieces of thin veneered plywood that was the backing for the furniture mirror (HERE same post) that I took apart some weeks ago. The wood was a backing for the glass mirror pieces and couldn't be seen when the mirror was installed so I am not sure why they used a veneer but anyway it's nice looking.
So after sanding the base and cutting the veneered wood Otto Jr. and I glued it all together:
I used a couple of those brass corner adornments that you get at the hardware store to finish off the bottom of the box where it attaches to the base. I also decided to limit the number of switches to just the functions I want. If you remember from the last post this clock has a ton of switches and most of them you just set for your time zone and forget. A couple are also for the alarm volume and the display brightness. I'll just solder those closed (or open) and leave them inside the box. For the other switches I'll use some push buttons for setting the time and a toggle switch for the Alarm On/Off. These are store bought switches and will work much better that the switches that came with the clock.
I have one of those elapsed time meters that have a 10 year battery in them that I want to add as well. That is the little square black thing in the lower right of the picture. These just count the amount of time that you apply power to them and are used in machinery to show the total powered on time of the system. I think it would be neat to add that to this clock as well so I cut a hole in the wood box for it. This will show the total number of hours that the clock has been running since the time I finish it!!! Wow that is great information isn't it!?!?!
The last piece of neat stuff that I am considering is the spiral egg shaped metal thing you see in the picture. I got a couple of those from a piece of furniture that someone threw in a vacant lot near my house a couple of years ago. There were two of these screwed into the tops of what looked like bed posts. They looked neat so i took them. Anyway I think once I have made a top for the box I'll put one of them on top and cover it with a small flower bowl that has spirals in the opposite direction. So the spiral metal piece will be inside the bowl and maybe I'll add some lights and a motor so it spins. It makes interesting refraction / reflection patterns because the spirals of the metal egg and the bowl are in opposite directions.
The next steps in this little project I think are to finish off the box with bits and pieces of brass and whatever else looks good and stain the wood. I'm going to try and do a bit of an antique look to it and 'dirty' up the brass. I also need to think about what extra lights and other things will look good. Maybe the holes around the base should glow red and the spinning-egg-in-the-bowl should have some lights.
Blog Template: This is a interesting coincidence as I have been itching to spice up the blog a bit but I don't want to take (and don't have the) time to figure out how to edit the raw HTML, CSS jibberish that you have to deal with. Well the other day Blogger apparently released a template editor that is easy to use and comes with some neat layouts. So I played around a little with that and the blog as you now see it is the result. Not too big of a change but still a little more interesting!
That's all for now...

Sunday, March 21, 2010

More Junk from the Garage.... and a Alarm Clock...

Another week has gone by and aside from working (2 jobs) and sleeping I have not had much time to do anything on my projects. This isn't necessarily a bad thing... just a statement. On opportunity that has presented itself if the pile of parts seen below.

What is all that you may ask? A pile of parts with a digital alarm clock being the focus. The clock works but the switches on it are really hard to switch. Sometimes you have to pick the clock up off the nightstand and put some muscle into actuating the switches. It's a good clock with a really annoying alarm and easy to read big dial. Lots'a fun in the wee hours of the morning when it wakes you up but turning it on or off is a chore.
In total there are a bunch of switches and buttons on it. 4 buttons for setting: the alarm, the time, and the up and down buttons for each. Additionally it has 3 DPST switches for the Alarm on/off, Dimmer hi/low and volume hi/low. Also of course is the snooze button. These are all located on the face and top of the clock right where you would expect them. On the bottom is a daylight savings time switch that is labeled On, Off and Old right next to a time zone switch that has: HAST, AKST, PST, MST, CST, EST and AST. I guess each one of those is for a different time zone of the globe. One of the features of this nifty clock is it "knows" where it is and can adjust itself accordingly. Fun but overly complicated.
The difficulty in fixing the hard to switch switches is they are part of the plastic case. These days it is less expensive to buy a switch and put it in a product than it is to mold a slider into the case and have a metal wiper scrape across pads on a PC board. The problem with doing this is if the molded parts are not super accurate or if the case doesn't quite fit together right then the switches become difficult or intermittent. That seems to be the problem with this one...
So rather than throw it away what I have decided to do is replace the switches and buttons with 'real' ones from other devices (my junk pile) and put the whole thing into a new and stylish enclosure of some sort. I figure while doing this I might as well embellish and adorn it with other interesting non clock related stuff and make it look cool!
We'll see how it turns out...

Friday, March 12, 2010

Broken Fruit Bowl Makes Good Mirror Frame

Well another exciting week has gone by and I have another small project to Blog about. As you may know if you read this on a regular basis I have a lot of 'irons in the fire' as they say and I have not stopped working on them... the TABLE that I am building and various other things... but those tend to be longer term things and sometimes I squeeze in other little things like this mirror project.

It all started when I was cleaning out some of the piles of junk that I have around the place and I found this broken Fruit Bowl Basket thing. The upper square portion was connected to the lower part with a bunch of metal wires and many of them were missing. In addition to parts being missing there was a big stain right in the middle of it where something sat for way too long and messes it up. So I took it apart and saved the  stained wood piece for another day and decided to use the square part for a mirror frame.

Not that I have a shortage of mirrors in my house and not that I'm so good looking that I need to see more of me... it just so happens that I have two very large pieces of mirror from a piece of furniture that I am not using and I thought that it might be fun to cut them up. Below is a picture of the two mirrors with one removed from the wood frame that they were in. Getting the mirror out and off the wood was a pain because the glue that they used to glue it in place was crazy strong and I had to cut it out with a knife that is sitting on the mirror in the picture below.

After getting the mirror out of the wood frame that it was in I cut it into a nicely sized piece for the fruit bowl frame. Cutting glass isn't all that fun and it takes a lot of practice. Actually you don't really cut it, it's more of a controlled breaking of the mirror (does that count as bad luck?). The important part of cutting glass other than gloves and eye protection is using lubrication on the GLASS CUTTER wheel. Light oil works good and it's a mess to get off the mirror after you roll the wheel across the glass!! Isn't that great?!
Back to the wood part. I used a little Dremel table that I have to hold my Dremel with a router bit in it to cut a groove in the wood frame. If you don't have a Dremel table I don't really recommend that you get one. They don't seem to work very well unless you are doing really really light work. The other problem that I have with the table is you can't adjust the Dremel height very far as there is not much travel in the adjustment. Also the way they hold the Dremel in the table is with clamps that seem to grab the Dremel motor in the wrong place so when you tighten it down the motor stops running correctly or stops all together.
OK once I had the groove in the square wood piece cut out and sized to the glass piece pretty good I had to make some critical design decisions, like what to do about the wood. I personally like the wood grain look but in this case the wood grain was looking nasty and there was about a bizillion coats of some kind of plastic sealer on it to protect it from the fruit. I decided to sand a few coats of the plastic off the wood and rough it up a bit. Then I sprayed a light coat of black spray paint on it and let it dry. This black coat was an undercoat for a finsh coat of American Accents Stone Creations spray paint. I had a can of this stuff that I was going to use on the HELMET project but never did. You can see the can in the picture above. This Stone Creations paint comes out like cotton candy stringy goop and makes a very textured surface. This particular can that I have is primarily black but also specks of gray and white come out along with all the bumpy stringy stuff giving it a look of black cotton candy mixed with rubber cement boogers that is supposed to look like stone or rock. It doesn't really look like stone but it does look cool.
Once the Stone Creations stuff had dried I glued in the mirror piece with Loctite Stick'n Seal Waterproof Adhesive. This stuff isn't as good as the glue that was used in the original mirror frame but I think it will work pretty good. My piece of mirror is smaller and lighter and if it does fall out I'll just glue in a new piece because I have plenty of mirror left over (besides the broken parts I broke with cutting (breaking) it)
That all there is to this crazy thing... now I have to find a place to hang it - maybe a dark room with no light would be good.

Saturday, March 6, 2010

Linear Approximation Table for Cryptanalysis in MS Excel

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:
That converts the numbers from decimal to 8 bits of binary ones and zeros. Then I used this formula:
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:
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
' 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
'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
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