old-crypto home¶
This is all about old and ancient cryptographic systems, some of them well known Caesar system (the best know probably being rot13, rot3 being the one used by Emperor Caesar of Rome fame) or plain mono/polyalphabetic systems (generally with a keyword to generate scrambled alphabet) and even more obscure ones such as the VIC and Nihilists ciphers.
It is mostly academic work, just for fun. It is mostly compatible with 1.8.* but is developed on 1.9.2. 1.9.2 is the future!
For references, books and links, see Links.
What is implemented?¶
Please check the repository or the Activity pages often, they will be more up to date than this page.
For the moment class hierarchies exist for both keys and ciphers.
Key is the base class.
Skeyis for general substitution keys
Caesaris for Caesar -like keys, a shifted-alphabet based monoalphabetic substitution
SCKeyis a Straddling Checkerboard key
SQKeyis a Polybius square based substitution leading to plaintext letters being replaced by a bigram either letters (like ADFGVX) or numbers.
Playfairis the key part of the Playfair bigrammmatic cipher.
ChaoKeyis the dual-rotor/ring system used by the Chaocipher system, invented by J. F. Byrne in 1918. See Chaocipher home for more details.
TKeyis for transposition keys
VICKeyis for handling the complicated key schedule of the VIC cipher. It is still Work In Progress©®.
Cipher is the module handling all the ciphers classes
SimpleCipher is the base class, ciphertext is plaintext
Substitutionis the base class for substitution-based ciphers
Caesaris the well-known ordered monoalphabetic cipher with a default offset of 3
Polybiusis a more general square-based bigram-generating substitution. Its main use is for the ADFGVX cipher.
Playfairis the bigrammatic cipher used by the Brits & US during WWII, written by Charles Wheatstone.
StraddlingCheckerboardis the general straddling checkerboard system, primarely here for integration in the Nihilist ciphers.
ChaoCipherimplements the cipher usingKey::ChaoKey, as you can see, very simple now that we have theKey::foundation in place.
Wheatstoneimplements the mechanical cipher written by Wheatstone (of Playfair fame)
Transpositionis the simple word-based transposition
Then we have composite cipher using one or two systems together for better security:
NihilistTis the straddling checkerboard followed by transposition variant.
ADFGVXis the famous German cipher from World War I, using aPolybiussubstitution following by transposition.
Testing¶
This project is also used by the author as a test-bed for Test Driven Development. It didn't start that way but is now as best as I can.
362 [10:05] roberto@sidhe:HG/old-crypto> rake (in /Users/roberto/Src/Perso/HG/old-crypto) /opt/local/bin/ruby -w -Ilib "/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake/rake_test_loader.rb" "test/test_cipher.rb" "test/test_key.rb" Loaded suite /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake/rake_test_loader Started ................................................ Finished in 0.080716 seconds. 48 tests, 292 assertions, 0 failures, 0 errors
Behaviour Driven Development is also an interesting concept but is left for another time. Ruby has a lot of support for it so it should not be too difficult.
The current state of tests is now the following. Made some progress I believe...
433 [18:07] roberto@lonrach-2:HG/old-crypto> rake test_units /Users/roberto/.rvm/rubies/ruby-1.9.3-p125/bin/ruby -w -I"lib" -I"/Users/roberto/.rvm/gems/ruby-1.9.3-p125@ruby-1.9.3/gems/rake-0.9.2.2/lib" "/Users/roberto/.rvm/gems/ruby-1.9.3-p125@ruby-1.9.3/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb" "test/test_cipher.rb" "test/test_crypto_helper.rb" "test/test_key.rb" Run options: # Running tests: ............................................................................................. Finished tests in 0.154542s, 601.7782 tests/s, 3468.3128 assertions/s. 93 tests, 536 assertions, 0 failures, 0 errors, 0 skips
Our current code stats are
+----------------------+-------+-------+---------+---------+-----+-------+ | Name | Lines | LOC | Classes | Methods | M/C | LOC/M | +----------------------+-------+-------+---------+---------+-----+-------+ | Code | 1391 | 685 | 26 | 74 | 2 | 7 | | Units | 1522 | 984 | 27 | 119 | 4 | 6 | +----------------------+-------+-------+---------+---------+-----+-------+ | Total | 2913 | 1669 | 53 | 193 | 3 | 6 | +----------------------+-------+-------+---------+---------+-----+-------+ Code LOC: 685 Test LOC: 984 Code to Test Ratio: 1:1.4