/// <summary>
        /// Gets thumbprint of JWK
        /// </summary>
        /// <param name="alg">Default SHA256</param>
        /// <returns></returns>
        public byte[] GetThumbprint(AlgorithmsEnum alg = AlgorithmsEnum.SHA256)
        {
            var listKeys = new SortedList();

            if (KeyType != null)
            {
                listKeys.Add("kty", KeyType.Value.ToString());
            }
            if (Exponent != null)
            {
                listKeys.Add("e", Exponent);
            }
            if (Modulus != null)
            {
                listKeys.Add("n", Modulus);
            }
            if (Y != null)
            {
                listKeys.Add("y", Y);
            }
            if (X != null)
            {
                listKeys.Add("x", X);
            }
            if (EllipticCurve != null)
            {
                listKeys.Add("crv", EllipticCurve.Value.ToString());
            }
            if (KeyValue != null)
            {
                listKeys.Add("k", KeyValue);
            }
            var json = JsonConvert.SerializeObject(listKeys);

            byte[] thumbprint;
            switch (alg)
            {
            case AlgorithmsEnum.SHA256:
                SHA256 mySHA256 = SHA256.Create();
                thumbprint = mySHA256.ComputeHash(Encoding.UTF8.GetBytes(json));
                break;

            case AlgorithmsEnum.SHA1:
                SHA1 mySHA1 = SHA1.Create();
                thumbprint = mySHA1.ComputeHash(Encoding.UTF8.GetBytes(json));
                break;

            default:
                throw new ArgumentException($"Unsupported algorithm: {nameof(alg)}");
            }
            return(thumbprint);
        }
Exemple #2
0
        public void ApplyDithering(AlgorithmsEnum algorithm, byte threshhold)
        {
            // Create an instance of the specified dithering algorithm
            var algo = algorithm;
            var halftoneProcessor = DitherFactory.GetDitherer(algo, threshhold);

            var bitmap = ImageData.ToBitmap();

            // The big grind
            var dithered = halftoneProcessor.GenerateDithered(bitmap);

            // Update ImageData with dithered result
            SetImageData(dithered);

            // For Phoenix we don't care about size of logo in flash. Everything is static.
            Size = dithered.Rasterize().Length;
        }
Exemple #3
0
 private void ChangedUsedAlgorithm(object sender, SelectionChangedEventArgs e)
 {
     try
     {
         var usedAlgorithmText = ((ComboBoxItem)e.AddedItems[0]).Content.ToString();
         if (string.IsNullOrEmpty(usedAlgorithmText))
         {
             _usedAlgorithm = AlgorithmsEnum.MinMax;
         }
         else
         {
             _usedAlgorithm = (AlgorithmsEnum)Enum.Parse(typeof(AlgorithmsEnum), usedAlgorithmText);
         }
     }
     catch (Exception)
     {
         _usedAlgorithm = AlgorithmsEnum.MinMax;
     }
 }
Exemple #4
0
 public void SetAlg(int numAlg)
 {
    this.alg = (AlgorithmsEnum)Enum.Parse(typeof(AlgorithmsEnum), numAlg.ToString());
    Debug.Log("Algorithm changed to : " + alg.ToString());
 }
Exemple #5
0
        public static IDitherable GetDitherer(AlgorithmsEnum algorithm, byte threshold = 128)
        {
            switch (algorithm)
            {
            case AlgorithmsEnum.Atkinson:
                // 0,0,1,1,1,1,1,0,0,1,0,0
                return(new Dither(new byte[, ] {
                    { 0, 0, 1, 1 },
                    { 1, 1, 1, 0 },
                    { 0, 1, 0, 0 }
                }, 3, threshold, true));

            case AlgorithmsEnum.Burkes:
                // 0,0,0,8,4,2,4,8,4,2
                return(new Dither(new byte[, ] {
                    { 0, 0, 0, 8, 4 },
                    { 2, 4, 8, 4, 2 },
                }, 5, threshold, true));

            case AlgorithmsEnum.FloydSteinberg:
                // 0,0,7,3,5,1
                return(new Dither(new byte[, ] {
                    { 0, 0, 7 },
                    { 3, 5, 1 },
                }, 4, threshold, true));

            case AlgorithmsEnum.FloydSteinbergFalse:
                // 0,3,3,2
                return(new Dither(new byte[, ] {
                    { 0, 3 },
                    { 3, 2 },
                }, 3, threshold, true));

            case AlgorithmsEnum.JarvisJudiceNinke:
                // 0,0,0,7,5,3,5,7,5,3,1,3,5,3,1
                return(new Dither(new byte[, ] {
                    { 0, 0, 0, 7, 5 },
                    { 3, 5, 7, 5, 3 },
                    { 1, 3, 5, 3, 1 }
                }, 48, threshold));

            case AlgorithmsEnum.Sierra:
                // 0,0,0,5,3,2,4,5,4,2,0,2,3,2,0
                return(new Dither(new byte[, ] {
                    { 0, 0, 0, 5, 3 },
                    { 2, 4, 5, 4, 2 },
                    { 0, 2, 3, 2, 0 },
                }, 5, threshold, true));

            case AlgorithmsEnum.Sierra2:
                // 0,0,0,4,3,1,2,3,2,1
                return(new Dither(new byte[, ] {
                    { 0, 0, 0, 4, 3 },
                    { 1, 2, 3, 2, 1 },
                }, 4, threshold, true));

            case AlgorithmsEnum.SierraLite:
                // 0,0,2,1,1,0
                return(new Dither(new byte[, ] {
                    { 0, 0, 2 },
                    { 1, 1, 0 },
                }, 2, threshold, true));

            case AlgorithmsEnum.Stucki:
                // 0,0,0,8,4,2,4,8,4,2,1,2,4,2,1
                return(new Dither(new byte[, ] {
                    { 0, 0, 0, 8, 4 },
                    { 2, 4, 8, 4, 2 },
                    { 1, 2, 4, 2, 1 },
                }, 42, threshold));

            default:
                // Precisamos pelo menos fazer um bitmap de 1bpp, caso contrário o impresso terá lixo.
                return(new OneBPP(threshold));
            }
        }