Showing posts with label Enigma. Show all posts
Showing posts with label Enigma. Show all posts

Saturday, August 8, 2015

Enigma - Revisited

UPDATE:
See Below

I have watched and read several more articles regarding cryptography. Each suggest that any method that uses "reused keys" or "reused sheets" is doomed to be deciphered, especial with very fast computers available today. The Enigma Machine had a very large Key, one of 158,962,555,217,826,360,000 settings. Which is computed as:

5 * 4 * 3 * 26^3 * ( 26! / (6! * 10! * 2^10) ) = 158,962,555,217,826,360,000

Note: I did NOT verify the above expression :-)

It has been suggested that the use of the Enigma, which did NOT use a "reused key", had its own downfalls. The most fatal where the facts that any single character would never encrypt to itself, and the "day key" was transmitted twice, or read from a code book.  History may have been recorded very differently without these two flaws.

The mechanics of the Enigma changed the running "key" with each character as the message is encoded, which is good. But, the starting "day key" was normally transmitted in a predictable formant twice at the beginning of each day.

I have played with my software implementation of the Enigma Machine, and have recently realised that software does not have-to-have the "limitation" imposed on the original Enigma Hardware, which had only 26 letters, 3 or 4 mechanical wheels, and jumper wires to implement the cypher.

My software implementation "could" easily use all of the ASCII codes (256, or maybe even more), as many "wheels" as desired, and with coded jumpers (in wheels and plug-boards) that "could" encode to themselves.

I think, flaws could be removed, as  the "published" problems with the Enigma. And, it is easy to do, it is just a mater of some easy to implement software! A very long "day key" could be created with Diffie-Hellman key exchange that could be easily transmitted via the Internet. The Software Enigma could instantly encode and transmit a message the same way.

It was suggested that even with the knowledge of the internal working of the Enigma. it would have been a lot harder to break the code (if the flaws had been eliminated). The same is true with a software solution, the algorithm could be published without much fear.

I wonder: How long would it take to decipher text from my Greatly Expanded Software Enigma Implementation? With just 256 Letter Codes, 256 Wheels, and 1 plug-board?

The German Enigma Key would appear to be a VERY SMALL fraction of the size of the possible Keys with 256 Letter Codes and 256 Wheels.

Actually, I do not think that would/could ever be answered, the problem is just too big.

For now, Software algorithms are always fun to think about  :-)



UPDATE:

Maybe "it", the number of keys for a 256 Letter Codes and 256 Wheels would NOT too big to calculate, I think it would be about:

256! * 256^256 =
27722102253833147750378752929772591901157254707422810843994850662178\
68509346387893431488607772479277687787895866917592862787498012527341\
20202941212930977432442839904764004089399268000448724122711559911607\
60779312819264238191417519113442331359269075602333340924686925409483\
99343102411050829848501735482622253522121728830342877764078525005364\
11706629786567706584325065474995318449040370842738828586810575264794\
12348783633571725165157131881436322357402582839932654806407271765546\
89263529741167130237617046563306987828896526138415818160291921177505\
94348668287596740843119974305008513344652339955774268612605659633484\
22635140831895266181475491155749645385538913890911142141920032414770\
49936109897934583258064087400757197847628192792690203621377980075882\
62413792355253854197130918506290943714329430352099968868502454316347\
64297297921292809713502427667689713905790084360261562757916556588568\
03869079651490956618284957160374601554692062042172725556744686295735\
57378616587083471686842123962257930714832014899651587649367849037445\
00798192771870940669313631808910069334016000000000000000000000000000\
000000000000000000000000000000000000

Or, about: 2.77221 x 10^1140 Keys

This number is not as big as a "googolplex", but it is very large.

This was computed with the following on a Linux machine:

$ echo "`echo 256 | factorial` * `echo '256^256'`" | bc


-- Home Page: https://WA0UWH.blogspot.com

Friday, May 1, 2015

Enigma - Hardware Implemented in Software

For several years, actually more like 30, I have being fascinated with the workings of the Enigma Machine.

On several occasions I have toyed with a Enigma Machine software design, but was never able to build an accurate solution. I have a very specific implementation in mind. So far, nothing has worked correctly. But, I guess, I have had a low-grade mental effort constantly considering the problem.

About three years ago, Wardy posted his build of a hardware implementation. That renewed my interest, but even with more work on my software implementation, and even with still a lot more thinking, there was no real progress.

Recently, my friend Jeff - KO7M posted his Enigma Machine implementation, I purposely did NOT read his details, because I wanted to continue with my implementation without external insight. But then again, his efforts renewing my interest in my software implementation. I still have that specific implementation in mind that I wanted to pursue.

So now, after several weeks of casual work on my software Enigma Machine, it still does NOT work as expected, some character are encoded correctly, but many others are NOT.

So, . . .

At night, sometimes I wake up,  thinking about the problem. And each night I seem to understand a little bit more.

There are several ideas that have helped me understanding the Enigma Machines operation. To simplify, I like to think of it in terms of:
  • Forget the Plug Board, it is a simple character exchange.
  • Code Wheels act like a "Fixed Wired, but Rotating PlugBoard", with simple two-letter exchanges.
  • The logic of the rotation of wheels is easier to understand if I think about it like a PlugBoard without cables plugged in, that is, character are not exchanged (i.e., A-to-A, B-to-B, etc)
  •  And, the Reflector is a simple adjacent character exchange (i.e., A-to-B, C-to-D, etc)
  • The code algorithm from the Input-to-the-Reflector, and the Reflector-to-the-Output, should mirror each other.
  • All wheel advancement and algorithms use Clock Maths.
  • Exchange of characters can be implemented after a correct wheel advancement algorithm is found and implemented.

Last Night

Last night, I suddenly woke up, . . . and had a algorithmic solution I wanted to try. In about five minutes, I had it typed in (see below).


IT WORK!

With proper Settings, I can now correctly Encode and Decode any M3 and M4 Enigma message, as verified.

ABC AAA AAA --
VERYXCOOLXJEFFXCANXYOUXREADXTHISXX
RLXVTMMQARSTKDJADSKMLAPGCXBRPZZFPE

The following is the guts of my software Enigma Machine implementation:



# Get Message Character
$i = ord($m)-65;

# Inc Wheels as Necessary
@P[3] += 1;     # Increment with each character
@P[2] += ((@P[3]%26) == $Adv3_Static+1);
@P[1] += ((@P[2]%26) == $Adv2_Static+1);
@P[0] += 0;

$R3 = @P[3] % 26;
$R2 = @P[2] % 26;
$R1 = @P[1] % 26;
$R0 = @P[0] % 26;

# Do Enigma, Encode or Decode
$i = @PB[$i];
$i = (@WL3[($i+$R3)%26]+26-$R3)%26;
$i = (@WL2[($i+$R2)%26]+26-$R2)%26;
$i = (@WL1[($i+$R1)%26]+26-$R1)%26;
$i = (@WL0[($i+$R0)%26]+26-$R0)%26;
$i = @R[$i]; 
$i = (@WR0[($i+$R0)%26]+26-$R0)%26;
$i = (@WR1[($i+$R1)%26]+26-$R1)%26;
$i = (@WR2[($i+$R2)%26]+26-$R2)%26;
$i = (@WR3[($i+$R3)%26]+26-$R3)%26;
$i = @PB[$i];

# Show Light, The Encode Character
print chr($i+65);



I will post a complete listing, after I code a proper User Interface and implement Multi-Notch Wheel advancements.

There are some details of newer Enigma Machine versions that I will not try implement, but they should be simple.

Note: There are probably optimizations that could be used in the code (I am still learning python).

This has be a long, mentally challenging, and fun project. But now, I guess I need to find another  :-)


-- Home Page: https://WA0UWH.blogspot.com