Example #1
0
        public int CodingTypeUp(CodingType ct)
        {
            string str  = "";
            string str2 = str + " update XPM_Basic_CodeType set ";

            return(publicDbOpClass.ExecSqlString((str2 + " TypeName='" + ct.TypeName + "',Remark='" + ct.Remark + "',SignCode='" + ct.SignCode + "'") + " where TypeID=" + ct.TypeID));
        }
Example #2
0
 protected void Page_Load(object sender, EventArgs e)
 {
     this.hdnstate.Value = base.Request.QueryString["r"];
     this._CodeList      = this.HdnCodeUse.Value.Split(new char[]
     {
         '^'
     });
     if (!this.Page.IsPostBack)
     {
         if (base.Request.Params["tid"] == null || base.Request.Params["w"] == null)
         {
             this.JS.Text = "alert('参数错误');window.returnValue=false;window.close();";
             return;
         }
         this.TypeID          = Convert.ToInt32(base.Request.Params["tid"]);
         this.HdnTypeID.Value = this.TypeID.ToString();
         CodingAction codingAction = new CodingAction();
         CodingType   codingType   = codingAction.QuerySingleCodingType(this.TypeID);
         this.hfldSignCode.Value = codingType.SignCode;
         if (base.Request.Params["w"] == "0")
         {
             this.BtnClose.Visible = false;
         }
         this.Page_CustomInit();
         this.TblCodeTree_Create(true);
         this.BtnDel.Attributes["onclick"] = "javascript:if(!confirm('删除该数据可能造成数据不完整,\\r\\n 确定要删除当前选中数据吗?')){return false;}";
     }
 }
        public static CalculationResult StartCalculations(string input, MonoAlphabet alpha,
                                                          EncoderType encoderType, CodingType codingType, out IMonoAlphabet monoAlphabet)
        {
            var result = Empty;

            var alphabetInfo = "";

            if (alpha == MonoAlphabet.Auto)
            {
                var autoDetected = Alphabet.DetectMonoFromString(input);
                alphabetInfo = $"За вхідним повідомленням визначено алфавіт: " +
                               $"{MonoAlphabets.GetName(autoDetected.Item2)}";
                monoAlphabet = autoDetected.Item1;
            }
            else
            {
                alphabetInfo = $"Задано алфавіт: {MonoAlphabets.GetName(alpha)}";
                monoAlphabet = Alphabet.GetMono(alpha);
            }

            result.CalculationsPipeline.AddRange(new string[]
            {
                "  --  ",
                "Початок обчислень...",
                $"Тип шифрування: {EncodingTypes.GetName(encoderType)}",
                $"Тип операції: {CodingTypes.GetName(codingType)}",
                alphabetInfo,
                $"Повідомлення: {input}"
            });

            return(result);
        }
Example #4
0
    private void dgDataBind()
    {
        CodingType codingType = this.ca.QuerySingleCodingType(Convert.ToInt32(this.TypeID));

        this.TxtClassName.Text = codingType.TypeName.ToString();
        this.TxtRemark.Text    = codingType.Remark;
        this.TxtSignCode.Text  = codingType.SignCode;
    }
 public TrithemiusControl(CodingType codingType, DecodeEncodeControl decodeEncodeControl)
 {
     InitializeComponent();
     lbCorrectAnsw.Visible = false;
     label9.Visible        = false;
     button1.Visible       = false;
     NextTest(false);
 }
Example #6
0
        public int CodingTypeAdd(CodingType ct)
        {
            string    sqlString = "select max(TypeID) + 1 from XPM_Basic_CodeType";
            DataTable table     = publicDbOpClass.DataTableQuary(sqlString);
            string    str2      = "";
            string    str3      = str2 + " insert into XPM_Basic_CodeType (TypeID,TypeName,IsVisible,IsValid,Remark,SignCode,Owner,VersionTime) values('" + table.Rows[0][0].ToString() + "','";
            string    str4      = str3 + ct.TypeName + "',1,1,'" + ct.Remark + "','" + ct.SignCode + "','000000','" + DateTime.Now.ToString() + "')";

            return(publicDbOpClass.ExecSqlString(str4 + " insert into XPM_Basic_NextID (SignCode,MaxID) values('" + ct.SignCode + "','" + table.Rows[0][0].ToString() + "') "));
        }
Example #7
0
 public CaesarControl(CodingType codingType, DecodeEncodeControl encodersForm)
 {
     InitializeComponent();
     _guid = Guid.NewGuid();
     _historyPresentation  = new HistoryPresentation();
     _questionCount        = 0;
     _correctQuestionCount = 0;
     _codingType           = codingType;
     _mainPresentation     = new MainPresentation();
     _encodersForm         = encodersForm;
     Init();
 }
Example #8
0
    private CodingType dgct()
    {
        CodingType codingType = new CodingType();

        codingType.TypeName = this.TxtClassName.Text.ToString();
        codingType.Remark   = this.TxtRemark.Text.ToString();
        codingType.SignCode = this.TxtSignCode.Text.ToString();
        if (this.type == "2")
        {
            codingType.TypeID = Convert.ToInt32(this.TypeID);
        }
        return(codingType);
    }
Example #9
0
        public CodingType QuerySingleCodingType(int typeID)
        {
            CodingType codingTypeFromDataRow = new CodingType();

            using (DataTable table = publicDbOpClass.DataTableQuary(" select * from XPM_Basic_CodeType where TypeID = " + typeID.ToString()))
            {
                if (table.Rows.Count == 1)
                {
                    codingTypeFromDataRow = this.GetCodingTypeFromDataRow(table.Rows[0]);
                }
            }
            return(codingTypeFromDataRow);
        }
Example #10
0
        /// <summary>
        /// Method GetCapacityFieldLength returns length by type of coding and version
        /// </summary>
        /// <returns>Return length of capacity field</returns>
        private int GetCapacityFieldLength(CodingType codingType)
        {
            switch (codingType)
            {
            case CodingType.Numeric:
                if (Version <= 9)
                {
                    return(10);
                }
                if (Version <= 26)
                {
                    return(12);
                }
                if (Version <= 40)
                {
                    return(14);
                }
                break;

            case CodingType.Alphanumeric:
                if (Version <= 9)
                {
                    return(9);
                }
                if (Version <= 26)
                {
                    return(11);
                }
                if (Version <= 40)
                {
                    return(13);
                }
                break;

            case CodingType.Byte:
                if (Version <= 9)
                {
                    return(8);
                }
                if (Version <= 26)
                {
                    return(16);
                }
                if (Version <= 40)
                {
                    return(16);
                }
                break;
            }
            return(0);
        }
Example #11
0
        //  private static Random _random = new Random();

        public RSAControl(CodingType codingType, DecodeEncodeControl encodersForm)
        {
            InitializeComponent();
            _historyPresentation = new HistoryPresentation();
            _guid                 = Guid.NewGuid();
            _countQuestion        = 0;
            _countCorrectQuestion = 0;
            _codingType           = codingType;
            tbE.Text              = "5";
            _mainPresentation     = new MainPresentation();
            _encodersForm         = encodersForm;

            Init();
        }
Example #12
0
        public int AddBasicCode(CodingInfo model, string _new)
        {
            int           codeMaxID = this.GetCodeMaxID(model.TypeID);
            StringBuilder builder   = new StringBuilder();

            if (string.IsNullOrEmpty(model.SignCode2))
            {
                CodingType type = this.QuerySingleCodingType(model.TypeID);
                if (type != null)
                {
                    model.SignCode2 = type.SignCode;
                }
            }
            builder.Append(" begin \n");
            if (model.IsDefault)
            {
                builder.Append(" update XPM_Basic_CodeList set IsDefault=0, VersionTime=getdate()\n");
                builder.Append(" where TypeID=@TypeID AND IsDefault=1; \n");
            }
            builder.Append(" insert into XPM_Basic_CodeList values( \n");
            builder.Append("\t\t@CodeID,@TypeID1,@ParentCodeID,@ParentCodeList,@CodeName,0,@IsFixed,@IsDefault,1,1,@Owner,getdate(),@I_xh, @SignCode2) \n");
            builder.Append(" update XPM_Basic_CodeList set ChildNumber = (select count(1) from XPM_Basic_CodeList  \n");
            builder.Append(" where (ParentCodeID=@ParentCodeID1 \n");
            builder.Append(" ) and (IsValid = 1) and (TypeID=@TypeID2 \n");
            builder.Append(" )),VersionTime=getdate() \n");
            builder.Append(" where (TypeID=@TypeID3 \n");
            builder.Append(" ) and (CodeID=@ParentCodeID3) \n");
            builder.Append(" end \n");
            int num2 = 0;

            if (model.IsDefault)
            {
                SqlParameter[] commandParameters = new SqlParameter[] { new SqlParameter("@TypeID", model.TypeID), new SqlParameter("@CodeID", codeMaxID), new SqlParameter("@TypeID1", model.TypeID), new SqlParameter("@ParentCodeID", model.ParentCodeID), new SqlParameter("@ParentCodeList", model.ParentCodeList + codeMaxID.ToString() + ","), new SqlParameter("@CodeName", model.CodeName), new SqlParameter("@IsFixed", model.IsFixed ? 1 : 0), new SqlParameter("@IsDefault", model.IsDefault ? 1 : 0), new SqlParameter("@ParentCodeID1", model.ParentCodeID), new SqlParameter("@TypeID2", model.TypeID), new SqlParameter("@TypeID3", model.TypeID), new SqlParameter("@ParentCodeID3", model.ParentCodeID), new SqlParameter("@I_xh", model.I_xh), new SqlParameter("@Owner", model.Owner), new SqlParameter("@SignCode2", model.SignCode2) };
                num2 = publicDbOpClass.ExecuteNonQuery(CommandType.Text, builder.ToString(), commandParameters);
            }
            else
            {
                SqlParameter[] parameterArray2 = new SqlParameter[] { new SqlParameter("@CodeID", codeMaxID), new SqlParameter("@TypeID1", model.TypeID), new SqlParameter("@ParentCodeID", model.ParentCodeID), new SqlParameter("@ParentCodeList", model.ParentCodeList + codeMaxID.ToString() + ","), new SqlParameter("@CodeName", model.CodeName), new SqlParameter("@IsFixed", model.IsFixed ? 1 : 0), new SqlParameter("@IsDefault", model.IsDefault ? 1 : 0), new SqlParameter("@ParentCodeID1", model.ParentCodeID), new SqlParameter("@TypeID2", model.TypeID), new SqlParameter("@TypeID3", model.TypeID), new SqlParameter("@ParentCodeID3", model.ParentCodeID), new SqlParameter("@I_xh", model.I_xh), new SqlParameter("@Owner", model.Owner), new SqlParameter("@SignCode2", model.SignCode2) };
                num2 = publicDbOpClass.ExecuteNonQuery(CommandType.Text, builder.ToString(), parameterArray2);
            }
            if (num2 > 0)
            {
                return(1);
            }
            return(0);
        }
        GetHistoryDetailByAnswers(string name, Guid guid)
        {
            List <Tuple <string, CodingType, HistoryDetailByAnswerEntity> > methodResult
                = new List <Tuple <string, CodingType, HistoryDetailByAnswerEntity> >();

            var detailCoddings =
                GetHistoryDetailByCoding(name).FirstOrDefault(p => p.Item2.GuidId == guid);

            if (detailCoddings == null)
            {
                return(methodResult);
            }

            CodingType codingType = detailCoddings.Item2.CodingType;

            return(detailCoddings.Item2.HistoryDetailByAnswerEntity
                   .Select(p => new Tuple <string, CodingType, HistoryDetailByAnswerEntity>
                               (name, codingType, p)).ToList());
        }
        private int GetMark(CodingType encoding,
                            List <HistoryDetailByCodingEntity> historyDetailByCodingEntities)
        {
            int encodingMark = 0;

            foreach (var codding in historyDetailByCodingEntities
                     .Where(p => p.CodingType == encoding))
            {
                int tempMark =
                    codding.HistoryDetailByAnswerEntity.Sum(p => p.Mark);

                if (tempMark > encodingMark)
                {
                    encodingMark = tempMark;
                }

                codding.Mark = tempMark;
            }

            return(encodingMark);
        }
        private void HelpbtnClickByTest(CodingType codingType)
        {
            panelQuestion.Controls.Clear();

            switch (_type)
            {
            case EncoderType.Caesar:
                panelQuestion.Controls.Add(new CaesarControl(codingType, this));
                break;

            case EncoderType.RSA:
                panelQuestion.Controls.Add(new RSAControl(codingType, this));
                break;

            case EncoderType.DSA:
                panelQuestion.Controls.Add(new DSAControl(codingType, this));
                break;

            case EncoderType.Vigenere:
                panelQuestion.Controls.Add(new VigenereControl(codingType, this));
                break;

            case EncoderType.Elgamal:
                panelQuestion.Controls.Add(new ElgamalControl(codingType, this));
                break;

            case EncoderType.Trithemius:
                panelQuestion.Controls.Add(new TrithemiusControl(codingType, this));
                break;

            case EncoderType.Stierlitz:
                panelQuestion.Controls.Add(new ShtirlitzControl());
                break;

            case EncoderType.Des:
                panelQuestion.Controls.Add(new DesControl());
                break;
            }
        }
Example #16
0
 public ServiceData(CodingType type, CorrectionLevel level)
 {
     CorrectionLevel = level;
     CodingType      = type;
 }
 public CaesarCalculator SetCodingType(CodingType type)
 {
     _codingType = type;
     return(this);
 }
Example #18
0
    private void TblCodeTree_Draw(DataTable dt)
    {
        TableRow   tableRow   = new TableRow();
        TableCell  tableCell  = new TableCell();
        CodingType codingType = CodeList.CodingAct.QuerySingleCodingType(this.TypeID);

        tableCell.Text = codingType.TypeName.ToString();
        tableRow.Cells.Add(tableCell);
        tableCell = new TableCell();
        tableRow.Cells.Add(tableCell);
        tableCell = new TableCell();
        tableRow.Cells.Add(tableCell);
        tableCell = new TableCell();
        tableRow.Cells.Add(tableCell);
        tableRow.Attributes["onclick"]     = "doClick(this,'" + this.TblCodeTree.ClientID + "');clickCodeRow('0','0',false,false);";
        tableRow.Attributes["onmouseover"] = "doMouseOver(this);";
        tableRow.Attributes["onmouseout"]  = "doMouseOut(this);";
        tableRow.CssClass = "grid_row";
        this.TblCodeTree.Rows.Add(tableRow);
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            DataRow dataRow = dt.Rows[i];
            tableRow       = new TableRow();
            tableCell      = new TableCell();
            tableCell.Text = dataRow["HeadImg"].ToString() + dataRow["CodeName"].ToString().Trim();
            tableCell.Wrap = false;
            tableRow.Cells.Add(tableCell);
            tableCell = new TableCell();
            if (dataRow["IsDefault"].ToString().ToLower() == "false")
            {
                tableCell.Text = "\t<img src=\"../../../images/white.gif\"  border=\"0\" style=\"height:15px;width:16px;\" />";
            }
            else
            {
                tableCell.Text = "<img src=\"../../../images/default.gif\" alt=\"默认项\" border=\"0\" style=\"height:15px;width:16px;\" />";
            }
            tableCell.HorizontalAlign = HorizontalAlign.Center;
            tableCell.Width           = 60;
            tableRow.Cells.Add(tableCell);
            tableCell                 = new TableCell();
            tableCell.Text            = dataRow["CodeID"].ToString().Trim();
            tableCell.Width           = 60;
            tableCell.HorizontalAlign = HorizontalAlign.Center;
            tableRow.Cells.Add(tableCell);
            tableCell                 = new TableCell();
            tableCell.Text            = dataRow["Owner"].ToString().Trim();
            tableCell.HorizontalAlign = HorizontalAlign.Center;
            tableRow.Cells.Add(tableCell);
            if ((int)dataRow["ParentCodeID"] != 0)
            {
                string text = dataRow["ParentCodeList"].ToString();
                tableRow.Attributes["id"] = text.Substring(0, text.LastIndexOf(",", text.Length - 2) + 1);
            }
            bool flag  = !(bool)dataRow["IsFixed"];
            bool flag2 = (int)dataRow["ChildNumber"] == 0 && !(bool)dataRow["IsFixed"] && !(bool)dataRow["IsDefault"];
            tableRow.Attributes["onclick"] = string.Concat(new string[]
            {
                "doClick(this,'",
                this.TblCodeTree.ClientID,
                "');clickCodeRow('",
                dataRow["CodeID"].ToString(),
                "','",
                dataRow["ParentCodeID"].ToString(),
                "',",
                flag.ToString().ToLower(),
                ",",
                flag2.ToString().ToLower(),
                ");"
            });
            tableRow.Attributes["onmouseover"] = "doMouseOver(this);";
            tableRow.Attributes["onmouseout"]  = "doMouseOut(this);";
            tableRow.Style.Add("display", dataRow["display"].ToString());
            tableRow.CssClass = "grid_row";
            this.TblCodeTree.Rows.Add(tableRow);
        }
    }
Example #19
0
        public static string HexToStr(this string hexCodedString, char seperator = ',', CodingType encodingType = CodingType.Unicode)
        {
            string retVal = "";

            if (hexCodedString == null || hexCodedString.Length == 0)
            {
                return(retVal);
            }
            List <byte> byteStream   = new List <byte>();
            var         tempByteVals = hexCodedString.Split(seperator);

            if (tempByteVals != null && tempByteVals.Length > 0)
            {
                for (int index = 0; index < tempByteVals.Length; index++)
                {
                    byteStream.Add(Convert.ToByte(tempByteVals[index], 16));
                }
            }

            if (encodingType == CodingType.Unicode)
            {
                retVal = Encoding.Unicode.GetString(byteStream.ToArray());
            }
            else
            {
                retVal = Encoding.UTF8.GetString(byteStream.ToArray());
            }
            return(retVal);
        }
Example #20
0
 public static string GetName(CodingType type) => _data[type];
Example #21
0
    private string GetSingCode(int typeId)
    {
        CodingType codingType = this.CodingAct.QuerySingleCodingType(typeId);

        return(codingType.SignCode);
    }
Example #22
0
        public IQuestionValue GenerateQuestion(CodingType codingType, EncoderType encodingType)
        {
            IQuestionValue value = new QuestionValue();

            int           countNumber = _random.Next(6, 10);
            StringBuilder question    = new StringBuilder();
            List <int>    primes      = new List <int>();

            switch (encodingType)
            {
            case EncoderType.Caesar:
                value.Description = RandomGenerator.NextENGMessage(5);
                break;

            case EncoderType.Vigenere:
                value.Description = RandomGenerator.NextENGMessage(5);
                break;

            case EncoderType.DiffiHelman:
                value = new DiffiHelmanQuestion();
                IDiffiHelmanQuestion diffiHelman = (IDiffiHelmanQuestion)value;
                primes = GetPrimes(203);

                diffiHelman.N = primes[_random.Next(0, primes.Count)];
                diffiHelman.Q = _random.Next(2, diffiHelman.N - 1);
                diffiHelman.X = _random.Next(11, 100);
                diffiHelman.Y = _random.Next(11, 100);
                value         = diffiHelman;
                break;

            case EncoderType.RSA:
                value = new DiffiHelmanQuestion();
                IDiffiHelmanQuestion diffiHelman1 = (IDiffiHelmanQuestion)value;
                primes         = GetPrimes(40);
                diffiHelman1.N = primes[_random.Next(2, primes.Count)];
                diffiHelman1.Q = _random.Next(2, diffiHelman1.N - 1);
                diffiHelman1.X = _random.Next(11, 40);
                value          = diffiHelman1;
                break;

            case EncoderType.Elgamal:
                primes = GetPrimes(203);
                value  = new ElgamalQuestion();
                IElgamalQuestion elgmal = (IElgamalQuestion)value;
                elgmal.P = primes[_random.Next(2, primes.Count)];
                elgmal.A = _random.Next(3, elgmal.P - 1);
                elgmal.B = _random.Next(1, elgmal.P - 2);
                elgmal.R = _random.Next(1, elgmal.P - 1);

                switch (codingType)
                {
                case CodingType.Encoding:
                    elgmal.Description = $"{_random.Next(2, 20)},{_random.Next(2, 200)}";
                    break;

                case CodingType.Decoding:
                    elgmal.Description = $"{_random.Next(2, 20)}";
                    break;
                }
                break;
            }

            return(value);
        }
Example #23
0
        public static string HexCodedStringToString(string hexCodedString, char seperator = ',', CodingType encodingType = CodingType.Unicode)
        {
            string      retVal       = "";
            List <byte> byteStream   = new List <byte>();
            var         tempByteVals = hexCodedString.Split(seperator);

            if (tempByteVals != null && tempByteVals.Length > 0)
            {
                for (int index = 0; index < tempByteVals.Length; index++)
                {
                    byteStream.Add(Convert.ToByte(tempByteVals[index], 16));
                }
            }

            if (encodingType == CodingType.Unicode)
            {
                retVal = Encoding.Unicode.GetString(byteStream.ToArray());
            }
            else
            {
                retVal = Encoding.ASCII.GetString(byteStream.ToArray());
            }

            return(retVal.Replace("\0", string.Empty));
        }
 public TrithemiusCalculator SetCodingType(CodingType type)
 {
     _codingType = type;
     return(this);
 }
Example #25
0
        public static string StrToHex(this string normalString, char seperator = ',', CodingType encodingType = CodingType.Unicode)
        {
            string retVal = "";

            if (string.IsNullOrWhiteSpace(normalString))
            {
                return(retVal);
            }

            byte[] bytes;
            if (encodingType == CodingType.Unicode)
            {
                bytes = Encoding.Unicode.GetBytes(normalString);
            }
            else
            {
                bytes = Encoding.ASCII.GetBytes(normalString);
            }

            retVal = BitConverter.ToString(bytes).Replace('-', seperator);

            return(retVal);
        }