Beispiel #1
0
        public void SinghCodeBook()
        {
            string ciphertext = new StringBuilder()
                                .Append("KJQPW CAISR XWQMA SEUPF OCZOQ")
                                .Append("ZVGZG WWKYE ZVTEM TPZHV NOTKZ")
                                .Append("HRCCF QLVRP CCWLW PUYON FHOGD")
                                .Append("DMOJX GGBHW WUXNJ EZAXF UMEYS")
                                .Append("ECSMA ZFXNN ASSZG WRBDD MAPGM")
                                .Append("RWTGX XZAXL BXCPH ZBOUY VRRVF")
                                .Append("DKHXM QOGYL YYCUW QBTAD RLBOZ")
                                .Append("KYXQP WUUAF MIZTC EAXBC REDHZ")
                                .Append("JDOPS QTNLI HIQHN MJZUH SMVAH")
                                .Append("HQJLI JRRXQ ZNFKH UIINZ PMPAF")
                                .Append("LHYON MRMDA DFOXT YOPEW EJGEC")
                                .Append("AHPYF VMCIX AQDYI AGZXL DTFJW")
                                .Append("JQZMG BSNER MIPCK POVLT HZOTU")
                                .Append("XQLRS RZNQL DHXHL GHYDN ZKVBF")
                                .Append("DMXRZ BROMD PRUXH MFSHJ")
                                .ToString();

            // Reflector: B
            // Wheel order: III I II (Possibly III II I)
            // Ring positions: 01 01 01 (A A A) (?)
            // Plug pairs: EI AS JN KL MU OT
            // Message key: OUA (?)
            // FInal key: BRS (?)
            string keyString = "B|III II I|01 01 01|EI AS JN KL MU OT";
            string ivString  = "O U A";
            string newIv     = "B R S";

            string plaintext = new StringBuilder()
                               .Append("DASXL OESUN GSWOR TXIST XPLUT")
                               .Append("OXXST UFEXN EUNXE NTHAE LTXEI")
                               .Append("NEXMI TTEIL UNGXD IEXMI TXDES")
                               .Append("XENTK ODIER TXIST XXICH XHABE")
                               .Append("XDASX LINKS STEHE NDEXB YTEXD")
                               .Append("ESXSC HLUES SELSX ENTDE CKTXX")
                               .Append("ESXIS TXEIN SXEIN SXZER OXEIN")
                               .Append("SXZER OXZER OXEIN SXEIN SXEIN")
                               .Append("SXXIC HXPRO GRAMM IERTE XDESX")
                               .Append("UNDXE NTDEC KTEXD ASSXD ASXWO")
                               .Append("RTXDE BUGGE RXWEN NXESX MITXD")
                               .Append("EMXUN TENST EHEND ENXSC HLUES")
                               .Append("SELXE NTKOD IERTX WIRDX ALSXR")
                               .Append("ESULT ATXDI EXUNT ENSTE HENDE")
                               .Append("NXSCH RIFTZ EICHE NXHAT")
                               .ToString();

            using SymmetricAlgorithm target = new EnigmaSymmetric()
                  {
                      Key = Encoding.Unicode.GetBytes(keyString),
                      IV  = Encoding.Unicode.GetBytes(ivString),
                  };
            string s = CipherMethods.SymmetricTransform(target, CipherTransformMode.Decrypt, ciphertext);

            Assert.Equal(plaintext, s);
            Assert.Equal(keyString, Encoding.Unicode.GetString(target.Key));
            Assert.Equal(newIv, Encoding.Unicode.GetString(target.IV));
        }
Beispiel #2
0
        public void DecryptCtor(string plaintext, string ciphertext, string newKey, string newIV)
        {
            using SymmetricAlgorithm target = new EnigmaSymmetric();
            string s = CipherMethods.SymmetricTransform(target, CipherTransformMode.Decrypt, ciphertext);

            Assert.Equal(plaintext, s);
            Assert.Equal(newKey, Encoding.Unicode.GetString(target.Key));
            Assert.Equal(newIV, Encoding.Unicode.GetString(target.IV));
        }
Beispiel #3
0
        [InlineData("B", "I", "B|II V I|23 15 02|HN IU JK LM OP TY", "K K R", "K K S")]                                          // Bugfix
        public void EncryptSettings(string plaintext, string ciphertext, string keyString, string ivString, string newIV)
        {
            using SymmetricAlgorithm target = new EnigmaSymmetric
                  {
                      Key = Encoding.Unicode.GetBytes(keyString),
                      IV  = Encoding.Unicode.GetBytes(ivString),
                  };
            string s = CipherMethods.SymmetricTransform(target, CipherTransformMode.Encrypt, plaintext);

            Assert.Equal(keyString, Encoding.Unicode.GetString(target.Key));
            Assert.Equal(newIV, Encoding.Unicode.GetString(target.IV));
            Assert.Equal(ciphertext, s);
        }
Beispiel #4
0
        public void Enigma_1941_07_07_19_25()
        {
            string ciphertext = new StringBuilder()
                                .Append("EDPUD NRGYS ZRCXN UYTPO MRMBO ")
                                .Append("FKTBZ REZKM LXLVE FGUEY SIOZV ")
                                .Append("EQMIK UBPMM YLKLT TDEIS MDICA ")
                                .Append("GYKUA CTCDO MOHWX MUUIA UBSTS ")
                                .Append("LRNBZ SZWNR FXWFY SSXJZ VIJHI ")
                                .Append("DISHP RKLKA YUPAD TXQSP INQMA ")
                                .Append("TLPIF SVKDA SCTAC DPBOP VHJK")
                                .ToString();

            // Reflector: B
            // Wheel order: II IV V
            // Ring positions:  02 21 12  (B U L)
            // Plug pairs: AV BS CG DL FU HZ IN KM OW RX
            // Message key: BLA
            // Final key: BRS
            string keyString = "B|II IV V|02 21 12|AV BS CG DL FU HZ IN KM OW RX";
            string ivString  = "B L A";
            string newIv     = "B R S";

            string plaintext = new StringBuilder()
                               .Append("AUFKL XABTE ILUNG XVONX KURTI ")
                               .Append("NOWAX KURTI NOWAX NORDW ESTLX ")
                               .Append("SEBEZ XSEBE ZXUAF FLIEG ERSTR ")
                               .Append("ASZER IQTUN GXDUB ROWKI XDUBR ")
                               .Append("OWKIX OPOTS CHKAX OPOTS CHKAX ")
                               .Append("UMXEI NSAQT DREIN ULLXU HRANG ")
                               .Append("ETRET ENXAN GRIFF XINFX RGTX")
                               .ToString();

            using SymmetricAlgorithm target = new EnigmaSymmetric
                  {
                      Key = Encoding.Unicode.GetBytes(keyString),
                      IV  = Encoding.Unicode.GetBytes(ivString),
                  };
            string s = CipherMethods.SymmetricTransform(target, CipherTransformMode.Decrypt, ciphertext);

            Assert.Equal(plaintext, s);
            Assert.Equal(keyString, Encoding.Unicode.GetString(target.Key));
            Assert.Equal(newIv, Encoding.Unicode.GetString(target.IV));
        }
Beispiel #5
0
        public void PracticalCryptography()
        {
            string ciphertext = new StringBuilder()
                                .Append("YXBMXADQBDBAAYIMKDODAYIXNBDQZF")
                                .Append("JKOLFVEEQBCLUUXDFVQYGKEYBVRHON")
                                .Append("JKPJMKUNLYLZUKBKJOAJTWVWMOMDPG")
                                .Append("VXEPUKXBVSGHROFOSBCNKEHEHAKWKO")
                                .Append("GWTBZFXSYCGSUUPPIZTRTFVCXZVCXT")
                                .Append("FLMTPTAQVMREGWSBFZBM")
                                .ToString();

            // Reflector: B
            // Wheel order: II V I
            // Ring positions:  23 15 02  (W O B)
            // Plug pairs: PO ML IU KJ NH YT
            // Message key: KJS
            // Final key: KPG
            string keyString = "B|II V I|23 15 02|HN IU JK LM OP TY";
            string ivString  = "K J S";
            string newIv     = "K P G";

            string plaintext = new StringBuilder()
                               .Append("THEENIGMACIPHERWASAFIELDCIPHER")
                               .Append("USEDBYTHEGERMANSDURINGWORLDWAR")
                               .Append("IITHEENIGMAISONEOFTHEBETTERKNO")
                               .Append("WNHISTORICALENCRYPTIONMACHINES")
                               .Append("ANDITACTUALLYREFERSTOARANGEOFS")
                               .Append("IMILARCIPHERMACHINES")
                               .ToString();

            using SymmetricAlgorithm target = new EnigmaSymmetric()
                  {
                      Key = Encoding.Unicode.GetBytes(keyString),
                      IV  = Encoding.Unicode.GetBytes(ivString),
                  };
            string s = CipherMethods.SymmetricTransform(target, CipherTransformMode.Decrypt, ciphertext.ToString());

            Assert.Equal(plaintext.ToString(), s);
            Assert.Equal(keyString, Encoding.Unicode.GetString(target.Key));
            Assert.Equal(newIv, Encoding.Unicode.GetString(target.IV));
        }