Skip to content

asilichenko/secom-cipher-gui

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

The SECOM cipher GUI application

This is a simple encipher/decipher GUI application that allows you to work with the SECOM cipher.

It was implemented according to the original Dirk Rijmenants's description.

Below you can find my modified version of that description.

The application contains this description as well - just click "Help" button.

Main window

About

System requirenments

  • Java 19

How to run

You have two options:

  • run GUI application: MainApp.java
  • run Demo example console application: DemoExampleApp.java

For developers

This software was created with JetBrains IntelliJ IDEA, GUI Forms as well.

Despite that fact, you can open it with any other IDE.

My IntelliJ IDEA was configured to autogenerate GUI code and special runner was added into Maven's dependencies.

This option you can find in the settings of your IntelliJ IDEA:

License

This software is licensed under GNU GENERAL PUBLIC LICENSE Version 3 or later.

https://www.gnu.org/licenses/gpl-3.0.html

An issue I faced

There was an issue I faced when I tried to render the help html page in the JEditorPane.

There are few very long chains of characters but JEditorPane cannot wrap such strings by default.

Moreover, by default JEditorPane cannot wrap text inside "pre" tags at all.

I had to look into this issue and I found a solution, so now everything is good rendered, as far as embedded HTML 3.2 allows.

Isolated sollution you can find in my other repository:

https://github.com/asilichenko/swing-html-paragraph-wrap

Screenshot of default state Screenshot of a result

The SECOM cipher

The SECOM cipher is a hand cipher to encrypt a message, containing letters, numbers and spaces.

The enciphering process consists of 3 phases:

  1. converting plain text into digits by the Straddling Checkerboard;
  2. simple Columnar Transposition;
  3. disrupted Columnar Transposition.

EXAMPLE

Plain text:

RV TOMORROW AT 1400PM TO COMPLETE TRANSACTION USE DEADDROP AS USUAL

Key Phrase:

MAKE NEW FRIENDS BUT KEEP THE OLD

INITIAL PHASE: KEY PHRASE PROCESSING

Take the first 20 letters of the key phrase (letters only, skip spaces) and split them into two halves. Within each half, number each letter in alphabetical order: starting from 1 and ending with 0 which represents the 10th letter in alphabetical order. The same letters should be numbered consecutively.

MAKENEWFRI ENDSBUTKEE
7162830495 3728109645

Sum them up digit by digit, ignoring carries.

 7162830495 - MAKENEWFRI
+3728109645 - ENDSBUTKEE
 ----------
 0880939030

Then generate a pseudo-random 50-digit sequence from the result using the Lagged Fibonacci generator:

  1. set the sequence to the given seed;
  2. sum up first two digits of the sequence, discard the carry;
  3. put the sum at the end of the sequence;
  4. repeat the process with the next pair of digits until 50 digits is generated.
0880939030 -> 8689229338…
0+8=8
8+8=(1)6
8+0=8
0+9=9
9+3=(1)2
3+9=(1)2
9+0=9
0+3=3
3+0=3
0+8=8
…

Resulting LFG-sequence:

0880939030 - the seed
---------- - generated digits
8689229338
4471412612
8185538730
9930815039
8238965327

PHASE 1: THE STRADDLING CHECKERBOARD

Take the last 10 digits of the LFG-sequence and number them as we do with letters in the beginning, 1 for the smallest digit and 0 (representing 10) for the largest. This numbering will be the Checkerboard key.

8238965327 - the last 10 digits of the LGF
8139065427 - the order of the digits

The default Checkerboard looks like this, where «*» - represents the space character:

1 2 3 4 5 6 7 8 9 10 - index numbers
--------------------
E S - T O - N I - A
B C D F G H J K L M
P Q R U V W X Y Z *
1 2 3 4 5 6 7 8 9 0

The first row of the checkerboard contains the highest frequency letters ESTONIA, with a blank in the 3rd, 6th and 9th positions.

Write down index numbers, the Checkerboard key and the first row of the default Checkerboard:

| 1 2 3 4 5 6 7 8 9 10 - index numbers
| 8 1 3 9 0 6 5 4 2 7  - the key
+---------------------
| E S - T O - N I - A

Shift the second row so that the letter B (the first letter of the row) is under the index 3 - the digit of the key above the first blank:

IDX | 1 2 3 4 5 6 7 8 9 10
KEY | 8 1 3 9 0 6 5 4 2 7
----+---------------------
 -  | E S  T O - N I - A
 3  | L M B C D F G H J K

Shift the third row so that the letter P is under the index 6 - the digit of the key above the second blank:

IDX | 1 2 3 4 5 6 7 8 9 10
KEY | 8 1 3 9 0 6 5 4 2 7
----+---------------------
 -  | E S - T O  N I - A
 3  | L M B C D F G H J K
 6  | W X Y Z * P Q R U V

Shift the fourth row so that the number 1 is under the index 2 - the digit of the key above the third blank:

IDX | 1 2 3 4 5 6 7 8 9 10
KEY | 8 1 3 9 0 6 5 4 2 7
----+---------------------
 -  | E S - T O - N I  A
 3  | L M b C D F G H J K
 6  | W X Y Z * p Q R U V
 2  | 0 1 2 3 4 5 6 7 8 9

The Straddling Checkerboard encoding

Replace each character of the plain text with numbers from the Checkerboard using the key:

R  V  *  T O M  O R  R  O W  *  A T *
64 67 60 9 0 31 0 64 64 0 68 60 7 9 60

1  4  0  0  P  M  *  T O *  C  O M  P
21 20 28 28 66 31 60 9 0 60 39 0 31 66

L  E T E *  T R  A N S A C  T I O N *
38 8 9 8 60 9 64 7 5 1 7 39 9 4 0 5 60

U  S E *  D  E A D  D  R  O P  *  A S
62 1 8 60 30 8 7 30 30 64 0 66 60 7 1

*  U  S U  A L
60 62 1 62 7 38

Note: since the final result will be divided into groups of 5, at this stage the sequence must be filled with trailing zeros to complete the last group of 5.

Result:

646760903106464068607960212028286631609060390316638898609647517399405606218603087303064066607160621627380

PHASE 2: COLUMNAR TRANSPOSITION

To determine the number of columns for the two transpositions, take the unique digits one by one, starting from the end of the LFG‑sequence, moving from left to right, add the digits until the result is greater than 9. The result is the width of the first columnar transposition. Continue the procedure to retrieve the width of the second columnar transposition:

…8238965[327] -> 7+2=9; 9+3=12
…82389[65]327 -> 5+6=11

Key sizes for the columnar transpositions are 12 and 11 respectively.

Columnar transposition keys generation

Take the 10 digits from the second half of the key phrase, and the 10 digits used for the straddling checkerboard and sum them up, digit by digit, ignoring carries:

 3728109645 - the second half of the key phrase
+8139065427 - the Checkerboard key
 ----------
 1857164062

Number the result digits (0 represents 10):

1857164062 - the sum result
1958264073 - the order

To get the keys for the columnar transpositions, use LFG‑sequence:

  1. write down the order;
  2. write down the sequence row by row within 10 columns;
  3. read out digits by columns according to established order to get the first and then the second transposition keys.
1958264073 - the order
---------- - the LFG-sequence
8689229338
4471412612
8185538730
9930815039
8238965327

The first key, 12 digits:

1: 84898
2: 24589
3: 82---
--------
848982458982

The second key, 11 digits:

3: --097
4: 92855
5: 878--
--------
09792855878

The first transposition

Simple columnar transposition:

  1. write down the key;
  2. number digits of the key as before;
  3. write down the numbers after the Straddling Checkerboard encoding row by row within the first key size;
  4. read out enciphered digits by columns in the order given by the key.
848982458982 - the key
   1     11
637181459202 - the order
------------ - the message sequence
646760903106
464068607960
212028286631
609060390316
638898609647
517399405606
218603087303
064066607160
621627380---

Result:

088089367 60167630 461031162 962364063 008900808 642665206 642987841 662699062 376095770 06314006 700083606 19636631

PHASE 3: THE SECOND TRANSPOSITION

The second transposition is a disrupted columnar transposition. The disruption means that you need to write down message digits row by row in the triangular areas which are defined by the order of the numbers in the key:

  1. start from the first row, the first column;
  2. write down digits one by one, until the position of the first number of the key;
  3. continue on the next row but write down one digit more than before;
  4. repeat the previous step until the entire row is filled;
  5. repeat the process for the second key number and so on until the rows run out;
  6. leave the last cells empty, if there are not enough digits to fill the full transposition block;
  7. then continue in the empty area starting from the first row, continue until the numbers run out.

Since we know that the message is 105 digits long and the key is 11 digits long, it means that we have to fill 9 rows with 11 digits, and 1 row with 6 digits, the last 5 spaces must be left empty.

First, fill the transposition block row by row with the numbers, avoiding the right triangular area that starts from position of the first number of the key:

09792855878 - the key
1  1
19401623758 - the order
-----------
0880        - write down 4 digits, until 1
89367       - write down one digit more
601676      - 6
3046103     - 7
11629623    - 8
640630089   - 9
0080864266  - 10
52066429878 - 11, full row
416626      - write down 6 digits, until 2
990623----- - only 6 digits on the last row

Now, just continue in the empty area from the first row:

09792855878 - the key
1  1
19401623758 - the order
-----------
08807609577
89367006314
60167600670
30461030083
11629623606
64063008919
00808642666
52066429878
41662636631
990623-----

Read out as usual for columnar transposition using the key:

7771938622 000320423 960038296 8314608060 717801673 6060606463 536069686 740369681 8900140219 0666260666 0863160549

Finally, the digits are divided in groups of 5 to get the fully encrypted message:

77719 38622 00032 04239 60038 29683 14608 06071 78016 73606 06064 63536 06968 67403 69681 89001 40219 06662 60666 08631 60549

MESSAGE DECRYPTION PROCESS

Firstly use the key phrase to calculate the keys for the Checkerboard and the two transpositions by the same procedure as for enciphering.

Next apply transpositions in reversed order:

  1. the second (disrupted) transposition:
    1. create the block for the transposition with the appropriate key length;
    2. fill in the encrypted message column by column, according to the 2nd transposition key;
    3. read off the message row by row, avoiding the right triangular areas;
    4. read off the digits from the right triangular areas, also row by row.
  2. the first (simple) transposition:
    1. fill in the block for transposition, created with the appropriate key length, column by column according to the 1st transposition key;
    2. read off the digits row by row.

Finally, convert the resulting sequence of digits to plain text, using the Checkerboard.

Remember that the end of the sequence could contain up to four zero digits added to complete a block of five.



Original text was written by Dirk Rijmenants
https://www.ciphermachinesandcryptology.com/en/secom.htm

Modified by: Oleksii Sylichenko, 2023