Ejemplo n.º 1
0
        //Determining the color of the current pixel on account of the given position: inside start/end pixels or outside them
        public Bitmap addColorToPixel(pixelInfo curPixelInfo, Bitmap curBitmap, List<Color> allColors, Encrypting curEncrypting)
        {
            bool noChange = false;
            int curIndex = curPixelInfo.i;
            if (curPixelInfo.startI > -1 && curIndex >= curPixelInfo.startI && curIndex <= curPixelInfo.endI)
            {
                noChange = true;
            }

            Color curColor = new Color();
            if (!noChange)
            {
                //The current pixel is randomly assigned
                curIndex = curPixelInfo.random.Next(0, allColors.Count - 1);

                while (IO.twoColorsAreEqual(allColors[curIndex], curEncrypting.curHashing.startColor)) //StartColor determines where the encrypted chunk starts/ends and thus cannot be used outside it
                {
                    curIndex = curPixelInfo.random.Next(0, allColors.Count - 1);
                }

                curColor = allColors[curIndex];
            }
            else
            {
                //This is part of the "encrypted chunk" and thus the pixels, as calculated so far, have to be added
                curPixelInfo.encryptedAdded = true;
                curIndex = curIndex - curPixelInfo.startI;
                curColor = curEncrypting.encryptedString[curIndex];

                if (curEncrypting.curHashing.startOffset.startOffsetCount == -1)
                {
                    //There is no offset; thus the color in the "offset position" cannot be curEncrypting.curHashing.startOffset.afterOffset
                    if (twoColorsAreEqual(curColor, curEncrypting.curHashing.startOffset.afterOffset) && !curEncrypting.curHashing.startOffset.replaceAfter.Value.IsEmpty)
                    {
                        if (curEncrypting.encryptingNumber > 0 && curIndex == curEncrypting.encryptingNumber + 1)
                        {
                            curColor = curEncrypting.curHashing.startOffset.replaceAfter.Value;
                        }
                    }
                }
            }

            curBitmap.SetPixel(curPixelInfo.x, curPixelInfo.y, curColor);

            return curBitmap;
        }
Ejemplo n.º 2
0
        //Method called by the one above to actually create the image
        private Bitmap createImage(int width, int height, Encrypting curEncrypting)
        {
            Hashing curHashing = curEncrypting.curHashing;
            List<Color> allColors = curHashing.charsVsColors.Values.ToList(); //Colors being considered in the current encryption: neither their number nor their order is kept constant

            curEncrypting = setBoundaryColors(curEncrypting); //Including the additional pixels surrounding the ones including the encrypted information

            //Accounting for the fact that the default size (500*500) is not enough to store all the required information
            int totSize = width * height;
            if (totSize < curHashing.curLength)
            {
                double ratio = Math.Ceiling(Math.Sqrt(Math.Ceiling((double)allColors.Count / curHashing.curLength)));
                height = Convert.ToInt32(Math.Ceiling(height * ratio));
                width = Convert.ToInt32(Math.Ceiling(width * ratio));
            }

            Bitmap outBitmap = new Bitmap(width, height);

            pixelInfo curPixel = new pixelInfo();

            //Determining the start/end pixels (where the encrypted string + additional info will be located)
            curPixel.startI = calculateStartI(width, height, curEncrypting);
            if (curEncrypting.encryptedString != null) curPixel.endI = curPixel.startI + curEncrypting.encryptedString.Count - 1;

            //Main loop populating the bitmap with all the pixels: ones containing encrypted information and all the other ones
            curPixel.i = -1;
            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    curPixel.i = curPixel.i + 1;
                    curPixel.x = x;
                    curPixel.y = y;

                    outBitmap = addColorToPixel(curPixel, outBitmap, allColors, curEncrypting);
                }
            }

            return outBitmap;
        }