Ejemplo n.º 1
0
        static void fonctionEsilv()
        {
            Encoding u8  = Encoding.UTF8;
            string   a   = "hello world";
            string   p   = "HELLO WORLD";
            int      iBC = u8.GetByteCount(p);

            byte[] byteellul      = { 64, 182, 134, 86, 198, 198, 242, 7, 118, 247, 38, 198, 64, 236, 17, 236, 17, 236, 17 };
            byte[] bytethonky     = { 32, 91, 11, 120, 209, 114, 220, 77, 67, 64, 236, 17, 236, 17, 236, 17 };
            byte[] bytemoipresque = { 32, 91, 11, 120, 209, 114, 220, 77, 67, 64, 236, 17, 236, 17, 236, 17, 236, 17, 236 };
            byte[] bytesa         = u8.GetBytes(p);
            //Console.WriteLine(binaireToNombre(bytesa));
            string b = "HELLO WORF";

            byte[] bytesb = u8.GetBytes(b);
            //byte[] result = ReedSolomonAlgorithm.Encode(bytesa, 7);
            //Privilégiez l'écriture suivante car par défaut le type choisi est DataMatrix
            byte[] result  = ReedSolomonAlgorithm.Encode(byteellul, 7, ErrorCorrectionCodeType.QRCode);
            byte[] result1 = ReedSolomonAlgorithm.Decode(bytesb, result);
            Console.WriteLine("Voici ce qui a été envoyé à Reed Solomon:");
            foreach (byte val in byteellul)
            {
                Console.Write(val + " ");
            }
            Console.WriteLine();
            Console.WriteLine("ce qui a été retourné:");
            foreach (byte val in result)
            {
                Console.Write(val + " ");
            }
            //foreach (int u in retour3) Console.Write(u + " ");
            Console.WriteLine();

            Console.ReadLine();
        }
Ejemplo n.º 2
0
        public static List <int> Encodage(string message)
        {
            List <int> retour = new List <int>();

            int[] mode       = { 0, 0, 1, 0 };
            int[] taille     = nombreToBinaire(message.Length, 9);
            int[] messageBit = stringToBit(message);
            foreach (int i in mode)
            {
                retour.Add(i);
            }
            foreach (int i in taille)
            {
                retour.Add(i);
            }
            foreach (int i in messageBit)
            {
                retour.Add(i);
            }

            int compteur = 0;

            while (retour.Count + 56 < 152 && compteur < 4)
            {
                retour.Add(0);
                compteur++;
            }
            compteur = 0;


            while (retour.Count % 8 != 0)
            {
                retour.Add(0);
            }
            int[] n236        = { 1, 1, 1, 0, 1, 1, 0, 0 };
            int[] n17         = { 0, 0, 0, 1, 0, 0, 0, 1 };
            int   tailletempo = retour.Count;

            for (int i = 0; i < (152 - tailletempo) / 8; i++)
            {
                if (compteur % 2 == 0)
                {
                    for (int j = 0; j < 8; j++)
                    {
                        retour.Add(n236[j]);
                    }
                }
                else
                {
                    for (int j = 0; j < 8; j++)
                    {
                        retour.Add(n17[j]);
                    }
                }
                compteur++;
            }

            byte[] messageBytes = octetToInt(retour);
            byte[] correction   = ReedSolomonAlgorithm.Encode(messageBytes, 7, ErrorCorrectionCodeType.QRCode);//pour hello world ça me donne pas la meme chose que le cdc
            retour.RemoveRange(95, 56);
            Console.WriteLine(retour.Count);
            for (int i = 0; i < correction.Length; i++)
            {
                foreach (int o in nombrebyteToBinaire(correction[i], 8))
                {
                    retour.Add(o);
                }
            }

            return(retour);
        }