//Contructor carrying out the main actions for this class public Encrypting(Color startColor, string temp_origText, IO curIO, int temp_encryptingNumber) { if (temp_origText == null || temp_origText.Trim().Length < 1) { errorMessage = "Please, introduce the string to be encrypted."; errors = true; return; } ignoredChars = new List<char>(); origText = temp_origText; modifiedText = origText; encryptingNumber = temp_encryptingNumber; //Creating the "hash table" (list of colors associated to the characters) has, logically, to be done before starting the encryption. //Note that the input string (its length) is also brought into picture while hashing curHashing = new Hashing(startColor, this, null, curIO); //Performing the actual encryption if (!curHashing.errors) { encryptText(startColor, origText); } else { this.errorMessage = curHashing.errorMessage; this.errors = true; } }
//Constructor with the required "pre-actions" (e.g., hashing) before starting the process public Decrypting(Color startColor, Bitmap curBitMap, IO curIO, int temp_encryptingNumber) { origBitmap = curBitMap; encryptingNumber = temp_encryptingNumber; curHashing = new Hashing(startColor, null, this, curIO); if (!curHashing.errors) { startDecrypting(curIO); } else { errorMessage = curHashing.errorMessage; errors = true; } }
//Decrypting process which, as far as it involves image management, is located in the IO class public void startDecrypting(IO curIO) { curIO.decryptImage(this); }
public Point startPixelOrig; //Stores the "fake start point", relevant while analysing the next pixels storing length information #endregion Fields #region Constructors //--- //Starting actions on account of the given process (encryption/decription) public Hashing(Color temp_startColor, Encrypting curEncrypting, Decrypting curDecrypting, IO temp_curIO) { startColor = temp_startColor; curIO = temp_curIO; curColors = new List<Color>(curIO.allKnownColors); startOffset = new startOffsetInfo(); if (curEncrypting != null) { if (curEncrypting.origText == null || curEncrypting.origText.Length < 1) { errors = true; return; } curLength = curEncrypting.origText.Length + 2 + (curEncrypting.origText.Length + 2).ToString().Length; //Length considered while decrypting encryptingNumber = curEncrypting.encryptingNumber; } else { if (curDecrypting.origBitmap == null) { errorMessage = "There was a problem while accessing the image file."; errors = true; return; } encryptingNumber = curDecrypting.encryptingNumber; pixelsToIgnore = new List<Point>(); //Preliminary validity check by looking for the startColor (in the right position) and determining the length (and the offset, if applicable) curIO.getBoundaryPixels(curDecrypting, this); if (curLength <= 0) { errors = true; return; } } calculateStartStep(); //Calculating curStep buildCharsVsColors(); //Building the hash table (dictionary with all the accounted characters and their equivalent color) which will be used in the current encryption/decryption process if (curDecrypting != null) { //For decryption. Confirming that the length value, calculated above, matches the information in the pixels enconding the actual length. //The reason for not having this analysis before is the fact that the charsVsColors is required if (!curIO.lengthIsOK(curDecrypting, this)) this.errors = true; } }
//Form load event populating the comboboxes with all the colours being considered (i.e., list of knownColors by removing repeated ones) private void Form1_Load(object sender, EventArgs e) { curIO = new IO(); cmbBxEncryptStart.DataSource = new List<Color>(curIO.allKnownColors); cmbBxDecryptStart.DataSource = new List<Color>(curIO.allKnownColors); }