arosspope / cipher-crypt

A cryptographic tomb of ciphers forgotten by time.
Apache License 2.0
42 stars 8 forks source link

Issue 30, with support for null chars #31

Closed avastmick closed 6 years ago

avastmick commented 6 years ago

This commit provides a fix for Issue #30 by providing support for null chars. As per issue comments, support for null chars is common in the implementations of the ADFGVX and Columnar Transposition ciphers. See Wikipedia entry on CT, for example.

I have increased the params for both ColumnarTransposition and ADFGVX to allow the passing of a null char. The null char may be anything but will error if the char exists in the keyword.

Using whitespace ' ', is allowed, however, it will mean the ciphers behave as per crate version 0.11.0, and the original problem of potentially trailing whitespace in the ciphertext persists. See ADFGVX test for both encrypt and decrypt using whitespace nulls:

#[test]
    fn encrypt_message_with_whitespace_nulls() {
        let a = ADFGVX::new((
            String::from("ph0qg64mea1yl2nofdxkr3cvs5zw7bj9uti8"),
            String::from("GERMAN"),
            String::from(" "),
        )).unwrap();

These tests show that the ciphertext trailing space problem persists when using whitespace nulls, but can be now avoided, by using either no nulls String::from(""), or using a different padding null char, such as \u{0}.

I have incremented the crate version to 0.12.0 as there are a fair amount of changes, including how the ADFGVX and ColumnarTransposition ciphers are initialised.

arosspope commented 6 years ago

Is there any particular reason as to why we've decided with the 'null chars' wording? To me, it seems much more intuitive to call them 'padding characters' (e.g. pad_char). Also, if it is a character, why are we passing it in as a string to the CT/ADFGVX constructor?

avastmick commented 6 years ago

Why am I calling it null chars, instead of padding, or pad chars?

When I did some research, that is what the cryptographical community term these extraneous characters. They are irrelevant characters, that only aide in processing the cipher, they are, null with respect to the message meaning.

In all cases, the padding was termed nulls so I went with that...

arosspope commented 6 years ago

Thanks for the clarification. If thats the consensus then we will go with that.