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)); }
public void EncodeDecode_100Times_OutputMatchesOriginal() { Prop.ForAll <byte[]>(bytes => { Z85.FromZ85String(Z85.ToZ85String(bytes, autoPad: true)); } ).QuickCheckThrowOnFailure(); }
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))); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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)")); }
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); }
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)); }
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); }
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); }
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); }); }
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)); } }
public Boolean EncodeDecodeAreDuals_Passing(Mod4Binary input) { var processed = Z85.Decode(Z85.Encode(input.Data)); return(processed.SequenceEqual(input.Data)); }
public Boolean EncodeDecodeAreDuals_Failing(Byte[] data) { var processed = Z85.Decode(Z85.Encode(data)); return(processed.SequenceEqual(data)); }
public void FromZ85String_InputSizeIncorrect_ThrowsException() { var encodedText = "WrongSize"; // Length - 1 not divisible by 5 var output = Z85.FromZ85String(encodedText); }
public void FromZ85String_PaddingCharacterNotDigit_ThrowsException() { var encodedText = "IllegalChrA"; // Padding char must be 0, 1, 2 or 3 var output = Z85.FromZ85String(encodedText); }
public void FromZ85String_PaddingCharacterIncorrectValue_ThrowsException() { var encodedText = "InvalidChr4"; // Padding char must be 0, 1, 2 or 3 var output = Z85.FromZ85String(encodedText); }