Home > College Algebra > Ciphers > Two-square Cipher (encoder / decoder) example

38. Two-square Cipher example (encoder / decoder) ( Enter your problem )
  1. Examples
Other related methods
  1. A1Z26 Cipher (Letter to number Cipher)
  2. ADFGVX Cipher
  3. ADFGX Cipher
  4. Affine Cipher
  5. Alberti Cipher
  6. Atbash Cipher
  7. Autokey Cipher / Autoclave Cipher
  8. Bacon Cipher
  9. Beaufort Cipher
  10. Bifid Cipher
  11. Caesar Cipher
  12. Chaocipher
  13. Columnar transposition Cipher
  14. Double Transposition Cipher
  15. Enigma machine Cipher
  16. Four Square Cipher
  17. Gronsfeld Cipher
  18. Hill Cipher
  19. Kamasutra Cipher | Vatsyayana Cipher
  20. Morse Code Translator
  21. Multiplicative Cipher | Decimation Cipher
  22. Nihilist Cipher
  23. Playfair Cipher
  24. Polybius Square Cipher
  25. Porta Cipher
  26. Rail fence Cipher
  27. ROT-5 Cipher
  28. ROT-13 Cipher
  29. ROT-18 Cipher
  30. ROT-47 Cipher
  31. ROT-N Cipher
  32. Running Key Cipher
  33. Substitution Cipher
  34. Tap code Cipher | Knock code Cipher
  35. Three Square Cipher
  36. Trifid Cipher
  37. Trithemius Cipher
  38. Two-square Cipher
  39. Vigenere Cipher

37. Trithemius Cipher
(Previous method)
39. Vigenere Cipher
(Next method)

1. Examples





1. Two-square Cipher encoder

Text : ABCD efghi
Key1 : key
Key2 : word
Padding Character : z


Solution:
The Two-Square Cipher is a digraph substitution cipher, which uses two grids to enctypt the message

Key1 = keyabcdfghilmnopqrstuvwxz

Key2 = wordabcefghiklmnpqstuvxyz

Grid-1
12345
1keyab
2cdfgh
3ilmno
4pqrst
5uvwxz

Grid-2
12345
1worda
2bcefg
3hiklm
4npqst
5uvxyz

Plaintext = abcdefghi
Split into pairs of letters (digraphs)
Pairs : ab cd ef gh i

Pad at end, if necessary
If one letter is left at the end, then pad to make it pair
Pairs : ab cd ef gh iz

Encryption :
For each bigram, find first letter in Grid-1 and second letter in Grid-2

Rule : If both letters are on the same row or column then reverse them, otherwise use Rectangle rule (Replace each letter with the one in its row, but in the other letter's column)

ab `=` a(G1,r1,c4), b(G2,r2,c1) `=>` w(G2,r1,c1), g(G1,r2,c4) `=` wg

cd `=` c(G1,r2,c1), d(G2,r1,c4) `=>` f(G2,r2,c4), k(G1,r1,c1) `=` fk

ef `=` e(G1,r1,c2), f(G2,r2,c4) `=>` d(G2,r1,c4), d(G1,r2,c2) `=` dd

gh `=` g(G1,r2,c4), h(G2,r3,c1) `=>` b(G2,r2,c1), n(G1,r3,c4) `=` bn

iz `=` i(G1,r3,c1), z(G2,r5,c5) `=>` m(G2,r3,c5), u(G1,r5,c1) `=` mu

Plaintext : abcdefghiz
Ciphertext : wgfkddbnmu

2. Two-square Cipher encoder

Text : hello world
Key1 : key
Key2 : word
Padding Character : z


Solution:
The Two-Square Cipher is a digraph substitution cipher, which uses two grids to enctypt the message

Key1 = keyabcdfghilmnopqrstuvwxz

Key2 = wordabcefghiklmnpqstuvxyz

Grid-1
12345
1keyab
2cdfgh
3ilmno
4pqrst
5uvwxz

Grid-2
12345
1worda
2bcefg
3hiklm
4npqst
5uvxyz

Plaintext = helloworld
Split into pairs of letters (digraphs)
Pairs : he ll ow or ld

Encryption :
For each bigram, find first letter in Grid-1 and second letter in Grid-2

Rule : If both letters are on the same row or column then reverse them, otherwise use Rectangle rule (Replace each letter with the one in its row, but in the other letter's column)

he `=` h(G1,r2,c5), e(G2,r2,c3) `=>` e(G2,r2,c3), h(G1,r2,c5) `=` eh

ll `=` l(G1,r3,c2), l(G2,r3,c4) `=>` l(G2,r3,c4), l(G1,r3,c2) `=` ll

ow `=` o(G1,r3,c5), w(G2,r1,c1) `=>` h(G2,r3,c1), b(G1,r1,c5) `=` hb

or `=` o(G1,r3,c5), r(G2,r1,c3) `=>` k(G2,r3,c3), b(G1,r1,c5) `=` kb

ld `=` l(G1,r3,c2), d(G2,r1,c4) `=>` l(G2,r3,c4), e(G1,r1,c2) `=` le

Plaintext : helloworld
Ciphertext : ehllhbkble





This material is intended as a summary. Use your textbook for detail explanation.
Any bug, improvement, feedback then Submit Here



37. Trithemius Cipher
(Previous method)
39. Vigenere Cipher
(Next method)





Share this solution or page with your friends.
 
 
Copyright © 2026. All rights reserved. Terms, Privacy
 
 

.