Draft

ADFGX UN-Simplified

Description:

THIS KATA IS PART TWO OF: ADFGX Simplified, SO YOU SHOULD COMPLETE IT FIRST!!!

The ADFGX Cipher is a pretty well-known Cryptographic tool, and is essentially a modified Polybius Square.

Rather than having numbers as coordinates on the table, it has the letters:

A, D, F, G, X

Also, because this is the SECOND step, and to help UN-simplify things, you WILL have to worry about a key, AND the corresponding columnar transposition. In this kata ;)

You will have to encrypt and decrypt a string into ADFGX format, and then rearrange it according to a given key.

adfgx_encrypt() and adfgx_decrypt() will be passed a string, plaintext and ciphertext respectively, an adfgx square, and a key, all of which will guide your operations.

Now for some examples to clear confusion:

adfgx_encrypt("helloworld", "bchigklnmoqprstuvwxyzadef", "key")

    A D F G X
   
A   b c h i g
D   k l n m o     
F   q p r s t  -> square (PLEASE NOTE, j SHOULD BE TREATED AS i)  
G   u v w x y  
X   z a d e f

"helloworld"   -> plaintext

EVALUATES TO:

      F  
          -> "AF"
A     h
--------------
          G 
               -> "XG"  
X         e 

AND SO FORTH...

Until you have: "AFXGDDDDDXGFDXFFDDXF"

At this point, you use the key to transpose the ADFGX text into the final ciphertext.

K E Y      -> key

A F X
G D D
D D D 
X G F      First you divide the letters among the columns of the key.
D X F
F D D
X F

Then you rearrange the columns according to the alphabetical order of the key.

E K Y (key -> eky in ascending order [a-z])

F A X
D G D
D D D
G X F
X D F
D F D
F X

Which results in the output ciphertext being:

adfgx_encrypt("helloworld", "bchigklnmoqprstuvwxyzadef", "key") 
==
"FDDGXDF AGDXDFX XDDFFD"

Now you must reverse the process through decryption:

adfgx_decrypt("GADFXFGDG FGGGAGFAX XDXXXGAG", "aczlmuqngoipvstkrwfxhdbey", "key") 

"GADFXFGDG FGGGAGFAX XDXXXGAG"   -> ciphertext

Arrange ciphertext in alphabetical columns of the key:

E K Y

G F X
A G D
D G X
F G X
X A X
F G G
G F A
D A G
G X

Rearrange to the original order of the key:

K E Y

F G X
G A D
G D X
G F X
A X X
G F G
F G A
A D G
X G

Reduce the columns:

"FGXGADGDXGFXAXXGFGFGAADGXG"
 FGXGADGDXGFXAXXGFGFGAADG

Solve coordinates using square:

    A D F G X

A   a c z l m
D   u q n g o     
F   i p v s t  -> square (PLEASE NOTE, j SHOULD BE TREATED AS i)  
G   k r w f x  
X   h d b e y

"FG" == "s"
"XG" == "e"

AND SO ON:

adfgx_decrypt("GADFXFGDG FGGGAGFAX XDXXXGAG", "aczlmuqngoipvstkrwfxhdbey", "key") 
==
"secretmessage"

PLEASE NOTE: ALL INPUT WILL BE VALID, NO NEED TO ERROR CHECK :D

TO AVOID SORTING INCONSISTENCIES, THERE WILL BE NO REPEATED LETTERS IN key

What are you waiting for?! Go create adfgx_encrypt() and adfgx_decrypt()!

Good Luck!

Cryptography
Algorithms

Similar Kata:

Stats:

CreatedSep 27, 2018
Warriors Trained47
Total Skips3
Total Code Submissions139
Total Times Completed12
Python Completions12
Total Stars2
% of votes with a positive feedback rating75% of 6
Total "Very Satisfied" Votes4
Total "Somewhat Satisfied" Votes1
Total "Not Satisfied" Votes1
Total Rank Assessments5
Average Assessed Rank
5 kyu
Highest Assessed Rank
4 kyu
Lowest Assessed Rank
6 kyu
Ad
Contributors
  • Caders Avatar
  • mauro-1 Avatar
Ad