コード例 #1
0
        public Property EncodeDecodeAreDuals_Collected(Mod4Binary input)
        {
            var processed = Z85.Decode(Z85.Encode(input.Data));

            return(processed.SequenceEqual(input.Data)
                   // gather individual sizes
                   .Collect(input.Data.Length));
        }
コード例 #2
0
 public void EncodeDecode_100Times_OutputMatchesOriginal()
 {
     Prop.ForAll <byte[]>(bytes =>
     {
         Z85.FromZ85String(Z85.ToZ85String(bytes, autoPad: true));
     }
                          ).QuickCheckThrowOnFailure();
 }
コード例 #3
0
        public Property EncodeDecodeAreDuals_Trivial(Mod4Binary input)
        {
            var processed = Z85.Decode(Z85.Encode(input.Data));

            return(processed.SequenceEqual(input.Data)
                   // identify a special case
                   .Trivial(input.Data.Any(b => b == 70)));
        }
コード例 #4
0
        public void FromZ85String_OutputSizeIsCorrect()
        {
            var encodedText        = "ABCDE12345";
            var expectedDecodeSize = 8; // 5 characters decode to 4 bytes

            var output = Z85.FromZ85String(encodedText);

            Assert.AreEqual(expectedDecodeSize, output.Length);
        }
コード例 #5
0
        public void FromZ85String_HelloWorld_Success()
        {
            var encodedString  = "HelloWorld";
            var expectedOutput = new byte[] { 0x86, 0x4F, 0xD2, 0x6F, 0xB5, 0x59, 0xF7, 0x5B };

            var output = Z85.FromZ85String(encodedString);

            CollectionAssert.AreEqual(expectedOutput, output);
        }
コード例 #6
0
        public void ToZ85String_HelloWorld_Success()
        {
            var bytes          = new byte[] { 0x86, 0x4F, 0xD2, 0x6F, 0xB5, 0x59, 0xF7, 0x5B };
            var expectedOutput = "HelloWorld";

            var output = Z85.ToZ85String(bytes);

            Assert.AreEqual(expectedOutput, output);
        }
コード例 #7
0
        public void ToZ85String_PaddingRequired_OutputSizeIsCorrect()
        {
            var input              = "HelloWorld";
            var inputBytes         = System.Text.Encoding.Default.GetBytes(input);
            var expectedEncodeSize = 15 + 1; // 4 bytes become 5, so with padding HelloWorld is 15 bytes encoded (+1 for padding value)

            var output = Z85.ToZ85String(inputBytes, true);

            Assert.AreEqual(expectedEncodeSize, output.Length);
        }
コード例 #8
0
        public void ToZ85String_NoPaddingRequired_OutputSizeIsCorrect()
        {
            var input              = "ABCD1234";
            var inputBytes         = System.Text.Encoding.Default.GetBytes(input);
            var expectedEncodeSize = 10; // 4 bytes become 5

            var output = Z85.ToZ85String(inputBytes);

            Assert.AreEqual(expectedEncodeSize, output.Length);
        }
コード例 #9
0
        public void EncodeDecode_PaddingRequired_Success()
        {
            var input      = "HelloWorld"; // 10 bytes - NOT divisible by 4 with no remainder
            var inputBytes = System.Text.Encoding.Default.GetBytes(input);

            var outputBytes = Z85.FromZ85String(Z85.ToZ85String(inputBytes, true));

            var output = System.Text.Encoding.Default.GetString(outputBytes);

            Assert.AreEqual(input, output);
        }
コード例 #10
0
        public void EncodeDecode_NoPaddingRequired_Success()
        {
            var input      = "RiAZ3bax"; // 8 bytes - divisible by 4 with no remainder
            var inputBytes = System.Text.Encoding.Default.GetBytes(input);

            var outputBytes = Z85.FromZ85String(Z85.ToZ85String(inputBytes));

            var output = System.Text.Encoding.Default.GetString(outputBytes);

            Assert.AreEqual(input, output);
        }
コード例 #11
0
        public Property EncodeDecodeAreDuals_Classified(Mod4Binary input)
        {
            var processed = Z85.Decode(Z85.Encode(input.Data));

            return(processed.SequenceEqual(input.Data)
                   // bucket by common sizes
                   .Classify(input.IsLarge(), "Large (64 .. ∞ bytes)")
                   .Classify(input.IsMedium(), "Medium (24 .. 60 bytes)")
                   .Classify(input.IsSmall(), "Small (8 .. 20 bytes)")
                   .Classify(input.IsTiny(), "Tiny (0 .. 4 bytes)"));
        }
コード例 #12
0
        public void EncodeDecode_1000Times_Max50Kb_OutputMatchesOriginal()
        {
            var config = Configuration.QuickThrowOnFailure;

            config.MaxNbOfTest = 1000;
            config.StartSize   = 0;
            config.EndSize     = 51200;

            Prop.ForAll <byte[]>(bytes =>
            {
                Z85.FromZ85String(Z85.ToZ85String(bytes, autoPad: true));
            }
                                 ).Check(config);
        }
コード例 #13
0
        public Property EncodeDecodeAreDuals_Combined(Mod4Binary input)
        {
            var processed = Z85.Decode(Z85.Encode(input.Data));

            return(processed.SequenceEqual(input.Data)
                   // identify a special case
                   .Trivial(input.Data.Any(b => b == 70))
                   // bucket by common sizes
                   .Classify(input.IsLarge(), "Large (64 .. ∞ bytes)")
                   .Classify(input.IsMedium(), "Medium (24 .. 60 bytes)")
                   .Classify(input.IsSmall(), "Small (8 .. 20 bytes)")
                   .Classify(input.IsTiny(), "Tiny (0 .. 4 bytes)")
                   // gather individual sizes
                   .Collect(input.Data.Length));
        }
コード例 #14
0
ファイル: Z85Encode.cs プロジェクト: lw000/zmq_guide
        public static void Z85Decode(string[] args)
        {
            //
            // Author: metadings
            //

            if (args == null || args.Length < 1)
            {
                args = new string[] { "nm=QNzY&b1A+]nf" };
            }

            string txt     = args[0];
            string decoded = Z85.Decode(txt);

            Console.WriteLine("{0}: {1}", txt, decoded);
        }
コード例 #15
0
ファイル: Z85Encode.cs プロジェクト: lw000/zmq_guide
        public static void Z85Encode(string[] args)
        {
            //
            // Author: metadings
            //

            if (args == null || args.Length < 1)
            {
                args = new string[] { "Hello World!" };
            }

            string txt     = args[0];
            string encoded = Z85.Encode(txt);

            Console.WriteLine("{0}: {1}", txt, encoded);
        }
コード例 #16
0
        public void SetOption_CurveSecretKey()
        {
            if (!ZContext.Has("curve"))
            {
                Assert.Ignore("Ignored due to missing curve support");
            }
            Assume.That(PlatformKind.Win32 == Platform.Kind); // TODO: fix the test and remove this

            DoWithUnconnectedPairSocket(socket =>
            {
                // TODO: the interface is confusing; Z85-encoded keys should always be strings
                byte[] publicKeyZ85, secretKeyZ85;
                Z85.CurveKeypair(out publicKeyZ85, out secretKeyZ85);
                socket.CurveSecretKey  = secretKeyZ85;
                byte[] secretKeyBinary = Z85.Decode(secretKeyZ85);
                CollectionAssert.AreEqual(secretKeyBinary, socket.CurveSecretKey);
            });
        }
コード例 #17
0
        private static string Hash([CanBeNull] string filename)
        {
            if (filename == null)
            {
                return(string.Empty);
            }

            using (var crypt = new SHA256Managed())
            {
                var result = crypt.ComputeHash(
                    crypt.ComputeHash(
                        new byte[] { 0, 1, 3, 5, 7, 9 }
                        .Concat(Encoding.ASCII.GetBytes(filename))
                        .ToArray())
                    .Concat(new byte[] { 34, 22, 230, 33, 33, 0 })
                    .ToArray());

                return(Z85.Encode(result));
            }
        }
コード例 #18
0
        public Boolean EncodeDecodeAreDuals_Passing(Mod4Binary input)
        {
            var processed = Z85.Decode(Z85.Encode(input.Data));

            return(processed.SequenceEqual(input.Data));
        }
コード例 #19
0
        public Boolean EncodeDecodeAreDuals_Failing(Byte[] data)
        {
            var processed = Z85.Decode(Z85.Encode(data));

            return(processed.SequenceEqual(data));
        }
コード例 #20
0
        public void FromZ85String_InputSizeIncorrect_ThrowsException()
        {
            var encodedText = "WrongSize"; // Length - 1 not divisible by 5

            var output = Z85.FromZ85String(encodedText);
        }
コード例 #21
0
        public void FromZ85String_PaddingCharacterNotDigit_ThrowsException()
        {
            var encodedText = "IllegalChrA"; // Padding char must be 0, 1, 2 or 3

            var output = Z85.FromZ85String(encodedText);
        }
コード例 #22
0
        public void FromZ85String_PaddingCharacterIncorrectValue_ThrowsException()
        {
            var encodedText = "InvalidChr4"; // Padding char must be 0, 1, 2 or 3

            var output = Z85.FromZ85String(encodedText);
        }