Saturday, April 11, 2015

Kriegsmarine M4 U-Boat message decryption

To test my M3/M4 Enigma machine code, I have given it the challenge of decoding an actual intercepted M4 message.

The message was intercepted by the British destroyer HMS Hurricane in the North Atlantic on 25 November 1942. This was during the ten months black-out which occurred after the introduction of the four-rotor Enigma M4. During that period, the codebreakers in Bletchley Park were unable to decrypt the Kriegsmarine radio traffic, encrypted with the new Enigma M4.

The original cipher text is show below, stripped of message indicator groups that preceded the message and were repeated at the end:


NCZW VUSX PNYM INHZ XMQX 
SFWX WLKJ AHSH NMCO CCAK 
UQPM KCSM HKSE INJU SBLK 
IOSX CKUB HMLL XCSJ USRR 
DVKO HULX WCCB GVLI YXEO 
AHXR HKKF VDRE WEZL XOBA 
FGYU JQUK GRTV UKAM EURB 
VEKS UHHV OYHA BCJW MAKL 
FKLM YFVN RIZR VVRT KOFD 
ANJM OLBG FFLE OPRG TFLV 
RHOW OPBE KVWM UQFM PWPA 
RMFH AGKX IIBG

The settings for the Enigma machine are as follows:

Enigma model: Kriegsmarine M4
Reflector: B
Rotors: Beta - II - IV - I
Stecker: AT BL DF GJ HM NW OP QY RZ VX
Ring settings: A-A-A-V
Rotor start position: V-J-N-A

I modified my test code to set the machine up with these settings thusly.  I will leave it to the reader to convert this to the Arduino example in my previous post.

int _tmain(int argc, _TCHAR* argv[])
{
// Clear and cipher text
char *szCipherText = 
"NCZW VUSX PNYM INHZ XMQX "
"SFWX WLKJ AHSH NMCO CCAK "
"UQPM KCSM HKSE INJU SBLK "
"IOSX CKUB HMLL XCSJ USRR "
"DVKO HULX WCCB GVLI YXEO "
"AHXR HKKF VDRE WEZL XOBA "
"FGYU JQUK GRTV UKAM EURB "
"VEKS UHHV OYHA BCJW MAKL "
"FKLM YFVN RIZR VVRT KOFD "
"ANJM OLBG FFLE OPRG TFLV "
"RHOW OPBE KVWM UQFM PWPA "
"RMFH AGKX IIBG";

char rgbBuf1[1024];

// Create a couple of instances to easily reset to default state 
Enigma e1; // Decode instance of engine

e1.setType(EnigmaTypeM4)
e1.setRotors(RotorB, RotorII, RotorIV, RotorI);
e1.setRingPos(LetterA, LetterA, LetterA, LetterV);
e1.setRotorPos(LetterV, LetterJ, LetterN, LetterA);
e1.setPlug(LetterA, LetterT); 
e1.setPlug(LetterB, LetterL);
e1.setPlug(LetterD, LetterF);
e1.setPlug(LetterG, LetterJ);
e1.setPlug(LetterH, LetterM);
e1.setPlug(LetterN, LetterW);
e1.setPlug(LetterO, LetterP);
e1.setPlug(LetterQ, LetterY);
e1.setPlug(LetterR, LetterZ);
e1.setPlug(LetterV, LetterX);

e1.doCipher(szCipherText, &rgbBuf1[0], 1024);
printf("Cipher: <%s>\n", szCipherText);
printf("Clear:  <%s>\n", &rgbBuf1[0]);
return 0;
}

I modified my Enigma class to output 4 letter code groups rather than the 5 letter groups typical of the M3 if the machine type is set to EnigmaTypeM4.

// Break into 4 or 5 character words\
if (++cchOut % (type == EnigmaTypeM3 ? 5 : 4) == 0) *pchOut++ = ' ';

The program output for this cypher text is as follows:

VONV ONJL OOKS JHFF TTTE 
INSE INSD REIZ WOYY QNNS 
NEUN INHA LTXX BEIA NGRI 
FFUN TERW ASSE RGED RUEC 
KTYW ABOS XLET ZTER GEGN 
ERST ANDN ULAC HTDR EINU 
LUHR MARQ UANT ONJO TANE 
UNAC HTSE YHSD REIY ZWOZ 
WONU LGRA DYAC HTSM YSTO 
SSEN ACHX EKNS VIER MBFA 
ELLT YNNN NNNO OOVI ERYS 
ICHT EINS NULL

When we rearrange the output to insert spaces as appropriate, we get the following:

VON VON JLOOKSJ HFFTTT EINS EINS DREI ZWO YY QNNS NEUN   
 INHALT XX BEI ANGRIFF UNTER WASSER GEDRUECKT Y WABOS X
 LETZTER GEGNERSTAND NUL ACHT DREI NUL UHR
 MARQU ANTON JOTA NEUN ACHT SEYHS DREI Y ZWO ZWO NUL GRAD Y ACHT SM Y STOSSE NACH X  
 EKNS VIER MB FAELLT Y NNN NNN OOO VIER Y SICHT EINS NULL

Now, converting abbreviations, spelled numbers, and so forth, we get the following:

Von Looks: Funktelegramm 1132/19

 Inhalt:

 Bei Angriff unter Wasser gedrueckt, Wasserbomben.  
 Letzter Gegnerstandort 08:30 Uhr,
 Marine Quadrat AJ 9863, 220 Grad, 8 Seemeilen, stosse nach.
 14 Millibar faellt, NNO 4, Sicht 10.
Running this through Google translate, we get the following English:
From Looks: radiogram 1132/19
  content:
  When attacked underwater pressured water bombs.
  Last opponents Location 08:30 clock,
  Marine Square AJ 9863, 220 degrees, 8 nautical miles, according to stumble.
  14 millibar falls, NNO 4, view 10th

Um, yeah...  Automatic translators pretty much suck...  Let's try this version:

From Looks: Radiogram 1132/19
Contents:
Forced to submerge during attack, depth charges,
Last enemy location 08:30h,
Naval Grid AJ 9863, 220 degrees, 8 nautical miles, (I am) following (the enemy).
(Barometer) 1014  Millibar (tendency) falling, North North East 4, visibility 10.

You can read all about this message and its history at this great page.  Have fun! 

No comments:

Post a Comment