コード例 #1
0
        public static string GenerateBlock(string VOTEHASH, string TIMESTAMP, string ADDRESS, string SALT)
        {
            string NEWBLOCK = "{\r\n";

            NEWBLOCK += "\t\"previoushash\":\"" + ADDRESS + "\",\r\n";
            NEWBLOCK += "\t\"votehash\":\"" + VOTEHASH + "\",\r\n";
            NEWBLOCK += "\t\"timestamp\":\"" + TIMESTAMP + "\",\r\n";
            NEWBLOCK += "\t\"blockhash\":\"" + SILICON64.GenerateHash(VOTEHASH + TIMESTAMP + ADDRESS + SALT) + "\"\r\n";
            NEWBLOCK += "}";
            return(NEWBLOCK);
        }
コード例 #2
0
        private void CalculateResult()
        {
            ResultText.Text = "";
            if (File.Exists(@Utility.DATAPATH))
            {
                string  ___BLOCKDATA = File.ReadAllText(@Utility.DATAPATH);
                JObject BLOCKCHAIN = JObject.Parse(___BLOCKDATA);
                JArray  items = (JArray)BLOCKCHAIN["blocks"];
                string  Currenthash, BlockHash, PrevHash;
                if (items.Count > 1)
                {
                    for (int i = 0; i < items.Count - 1; i++)
                    {
                        BlockHash = (string)items[i]["blockhash"];
                        PrevHash  = (string)items[i + 1]["previoushash"];
                        if (!BlocksChain.Validation(PrevHash, BlockHash))
                        {
                            Chainflag        = false;
                            ResultText.Text += "\r\n------------------------------------";
                            ResultText.Text += "\r\nCHAIN ERROR AT BLOCK : " + (i + 1).ToString();
                            ResultText.Text += "\r\n------------------------------------";
                            break;
                        }
                        else
                        {
                            Chainflag = true;
                        }
                    }
                    if (Chainflag)
                    {
                        for (int y = 1; y < items.Count; y++)
                        {
                            Currenthash = BlocksChain.GenerateBlockHash((string)items[y]["votehash"], (string)items[y]["timestamp"], (string)items[y]["previoushash"], Configuration.SaltValue);
                            if (BlocksChain.BlockValidation(Currenthash, (string)items[y]["blockhash"]))
                            {
                                ResultText.Text += "\r\n------------------------------------";
                                ResultText.Text += "\r\nCORRUPT DATA IN BLOCK : " + (y + 1).ToString();
                                ResultText.Text += "\r\n------------------------------------";
                                Dataflag         = false;
                                break;
                            }
                            else
                            {
                                Dataflag = true;
                            }
                        }
                    }
                    if (Chainflag && Dataflag)
                    {
                        ResultText.AppendText("\r\n-------------------------------------");
                        ResultText.AppendText("\r\nVALID BLOCK CHAIN -- COMPUTING RESULT");
                        ResultText.AppendText("\r\n-------------------------------------");
                    }

                    for (int z = 0; z < items.Count; z++)
                    {
                        for (int ID = 70001; ID <= 70005; ID++)
                        {
                            Thread.Sleep(500);
                            for (int UID = 10001; UID <= 10005; UID++)
                            {
                                //ResultText.Text += "\r\n";
                                if ((string)items[z]["votehash"] == SILICON64.GenerateHash(ID.ToString() + UID.ToString()))
                                {
                                    Console.Beep(700, 500);
                                    ResultText.AppendText("\r\n\r\nBLOCK - [" + (z + 1).ToString() + "]\r\n");
                                    ResultText.AppendText("\r\nVOTE HASH  >>" + (string)items[z]["votehash"]);
                                    ResultText.AppendText("\r\nBLOCK HASH >>" + (string)items[z]["blockhash"]);
                                    if (ID == 70001)
                                    {
                                        A++;
                                    }
                                    if (ID == 70002)
                                    {
                                        B++;
                                    }
                                    if (ID == 70003)
                                    {
                                        C++;
                                    }
                                    if (ID == 70004)
                                    {
                                        D++;
                                    }
                                    if (ID == 70005)
                                    {
                                        E++;
                                    }
                                    Thread.Sleep(1500);
                                    continue;
                                }
                            }
                        }
                    }

                    ResultText.Text += "\r\n\r\n";
                    Console.Beep(500, 2500);
                    ResultText.Text += "\r\n70001	ALPHA  : "+ A.ToString();
                    ResultText.Text += "\r\n70002	BETA   : "+ B.ToString();
                    ResultText.Text += "\r\n70003	DELTA  : "+ C.ToString();
                    ResultText.Text += "\r\n70004	GAMMA  : "+ D.ToString();
                    ResultText.Text += "\r\n70005	ECHO   : "+ E.ToString();
                }
                else
                {
                    ResultText.Text = "EMPTY CHAIN";
                }
            }
            else
            {
                ResultText.Text = "Blocks not found!!";
            }
        }
コード例 #3
0
        public void RemoteSend(int option)
        {
            Console.Beep(700, 1500);
            string  _CONFIGURATION_DATA_ = File.ReadAllText(@Configuration.CONFIGPATH);
            JObject ConfigurationData    = JObject.Parse(_CONFIGURATION_DATA_);
            JArray  ConfigItem           = (JArray)ConfigurationData["CONFIGURATION"];
            bool    flag = true;
            string  ID   = "";

            if (option == 1)
            {
                ID = SILICON64.GenerateHash("70001" + Utility.USERID);
            }
            else if (option == 2)
            {
                ID = SILICON64.GenerateHash("70002" + Utility.USERID);
            }
            else if (option == 3)
            {
                ID = SILICON64.GenerateHash("70003" + Utility.USERID);
            }
            else if (option == 4)
            {
                ID = SILICON64.GenerateHash("70004" + Utility.USERID);
            }
            else if (option == 5)
            {
                ID = SILICON64.GenerateHash("70005" + Utility.USERID);
            }
            else
            {
                MessageBox.Show("Invalid Option");
                flag = false;
            }
            if (flag)
            {
                string timestamp = DateTime.Now.ToString("yyyyMMddHHmmssffff");
                string Data      = ID + "$" + timestamp;


                for (int i = 0; i < ConfigItem.Count; i++)
                {
                    //Thread.Sleep(100);
                    int    PORT_NO   = Configuration.FetchPort(i);
                    string SERVER_IP = Configuration.FetchServer(i);
                    sentflag = true;
                    SendData(SERVER_IP, Data, PORT_NO);
                    //threads.Add(new Thread(() => SendData(SERVER_IP, Data, PORT_NO)));
                }
                if (sentflag)
                {
                    if (File.Exists(@Utility.DATAPATH))
                    {
                        string  _USER_DATA_ = File.ReadAllText(Utility.DATAPATH);
                        JObject UserData    = JObject.Parse(_USER_DATA_);
                        JArray  items       = (JArray)UserData["UserBlock"];
                        Console.WriteLine("STATUS UPDATED : " + Utility.BLOCKID.ToString());
                        Console.WriteLine("USER   ID      : " + ((int)items[Utility.BLOCKID]["ID"]).ToString());
                        Console.WriteLine("User Name      : " + (string)items[Utility.BLOCKID]["Name"]);
                        items[Utility.BLOCKID]["Status"] = SILICON64.GenerateHash((string)items[Utility.BLOCKID]["ID"] + (string)items[Utility.BLOCKID]["Name"] + "0");
                        using (FileStream FILEHANDLE = File.Create(@Utility.DATAPATH))
                        {
                            string FileText = "{\"UserBlock\":\r\n" + items.ToString() + "\r\n}";
                            Byte[] ByteData = new UTF8Encoding(true).GetBytes(FileText);
                            FILEHANDLE.Write(ByteData, 0, ByteData.Length);
                            FILEHANDLE.Close();
                        }
                    }
                }
                this.Hide();
            }
        }
コード例 #4
0
 public static string GenerateBlockHash(string votehash, string timestamp, string Address, string Salt)
 {
     return(SILICON64.GenerateHash(votehash + timestamp + Address + Salt));
 }
コード例 #5
0
ファイル: Scan.cs プロジェクト: prashanth8403/Plutonium
 private void timer1_Tick(object sender, EventArgs e)
 {
     if (Imager.Image != null)
     {
         Result InputRead = ReadQR.Decode((Bitmap)Imager.Image);
         try
         {
             if (InputRead.ToString().Trim() != "")
             {
                 QRCode = InputRead.ToString().Trim();
             }
             Clock.Stop();
             qrcode();
             label1.Text = QRCode;
             if (QRCode == "close$")
             {
                 string  _CONFIGURATION_DATA_ = File.ReadAllText(@Configuration.CONFIGPATH);
                 JObject BLOCKCHAIN           = JObject.Parse(_CONFIGURATION_DATA_);
                 JArray  items = (JArray)BLOCKCHAIN["CONFIGURATION"];
                 for (int i = 0; i < items.Count; i++)
                 {
                     int    PORT_NO   = Configuration.FetchPort(i);
                     string SERVER_IP = Configuration.FetchServer(i);
                     SendLock(SERVER_IP, PORT_NO);
                     label1.Text = "SYSTEM LOCKED";
                     Clock.Stop();
                     Imager.Image = null;
                 }
             }
             else
             {
                 //
                 //
                 Utility.USERID = Convert.ToInt32(QRCode);
                 //
                 //
                 if (Utility.USERID >= 10001 && Utility.USERID <= 10006)
                 {
                     string  ___BLOCKDATA = File.ReadAllText(@Utility.DATAPATH);
                     JObject BLOCKCHAIN   = JObject.Parse(___BLOCKDATA);
                     JArray  items        = (JArray)BLOCKCHAIN["UserBlock"];
                     for (int x = 0; x < items.Count; x++)
                     {
                         //Console.WriteLine((string)items[x]["Status"]);
                         //Console.WriteLine(SILICON64.GenerateHash((string)items[x]["ID"] + (string)items[x]["Name"] + "1"));
                         if (Utility.USERID == (int)items[x]["ID"])
                         {
                             Console.WriteLine((string)items[x]["Status"]);
                             Console.WriteLine(SILICON64.GenerateHash((string)items[x]["ID"] + (string)items[x]["Name"] + "1"));
                             if ((string)items[x]["Status"] == SILICON64.GenerateHash((string)items[x]["ID"] + (string)items[x]["Name"] + "1"))
                             {
                                 Utility.BLOCKID = x;
                                 //this.Hide();
                                 Ballot _ballot = new Ballot();
                                 _ballot.Visible = true;
                                 break;
                             }
                             else if ((string)items[x]["Status"] == SILICON64.GenerateHash((string)items[x]["ID"] + (string)items[x]["Name"] + "0"))
                             {
                                 ErrorTag.Text = "User already Voted";
                                 Console.Beep(2500, 1500);
                             }
                             else
                             {
                                 ErrorTag.Text = "Invalid User Data";
                                 Console.Beep(2500, 1500);
                             }
                         }
                     }
                 }
             }
         }
         catch (Exception Exeception)
         {
             //MessageBox.Show(Exeception.Message);
         }
     }
 }