简体   繁体   English

即使值更改,列表也会保持相同的第一个值

[英]List keeps getting same first value, even though value changes

I'm writing an encryptor code and to be more specific: 我正在编写一个加密器代码,更具体地说:
I'm currently writing a check that encrypts the letters and then decrypts them in order to see whether they can be, and then compares the decrypted output to the initial input. 我当前正在写一个检查,对字母进行加密,然后对它们解密,以查看它们是否可以,然后将解密后的输出与初始输入进行比较。
I check this because the decryption formula uses cos^-1 which can't take use values. 我检查这是因为解密公式使用cos^-1 ,而不能使用使用值。

Unfortunately, the list of the ints of the letters (a=1, b=2, z=26, etc) keeps adding the same first value, even though the value changes. 不幸的是,即使值更改,字母的整数列表(a=1, b=2, z=26, etc)仍会添加相同的第一个值。

Part of the code: 部分代码:

foreach(int x in LetInt) {
    DoubInt++;

    try {
        CheckLetInt.Add(Convert.ToInt64(Math.Acos(Math.Pow((((Math.Tan((x+1) / (180/Math.PI)) / Math.Sin((x+1) / (180/Math.PI))) * (Math.Cos(A / (180/Math.PI)) * B)) - 1) / (Math.Cos(A / (180 / Math.PI)) * B), -1)) * (180 / Math.PI)));
        Console.WriteLine("Correct number:" + Convert.ToInt64(Math.Acos(Math.Pow((((Math.Tan((x+1) / (180/Math.PI)) / Math.Sin((x+1) / (180/Math.PI))) * (Math.Cos(A / (180/Math.PI)) * B)) - 1) / (Math.Cos(A / (180 / Math.PI)) * B), -1)) * (180 / Math.PI)));
        Console.WriteLine("List content:" + CheckLetInt[DoubInt - 1]);
        CheckLetter.Add(LetPos[Convert.ToInt64(CheckLetInt[DoubInt - 1]) - 1]);
    } catch(Exception) {
        ValueError.Visible = true;
        ClearAll();
        Console.WriteLine("Caught.");
    }
}

Output: 输出:

输出量

Anyone know what's going on? 有人知道发生了什么吗?
The "Correct Number" and "List Content" formulae are the same. “正确数字”和“列表内容”的公式相同。

Link to the project (it's a program so the code by itself doesn't work) 链接到项目(这是一个程序,因此代码本身不起作用)

Link to the code by itself 自己链接到代码

Later down in the loop you do: 稍后在循环中执行以下操作:

if(string.Join("", CheckLetter) == string.Join("", Letters.ToArray())) {
     ...
} else {
     ClearAll();
}

You never modify Letters in loop, but you do modify CheckLetter, so this will mostly return false, calling the ClearAll() method. 您永远不会修改循环中的Letters,但是您确实会修改CheckLetter,因此大多数情况下将返回false,从而调用ClearAll()方法。

In ClearAll() you set DoubInt back to zero - hence always showing the first entry 在ClearAll()中,将DoubInt设置回零-因此始终显示第一个条目

        DoubInt = 0;

Note that this is not a good way to 'encrypt' anything. 请注意,这不是“加密”任何内容的好方法。 If you are just playing around then okay, but if you are trying to learn cryptography you should read up on same basics first if you think this is 'encryption' 如果您只是在玩耍,那就好了,但是,如果您想学习密码学,那么如果您认为这是“加密”,则应该先阅读相同的基础知识。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 即使节点发生更改,xmlNode.SelectSingleNode也始终返回相同的值 - xmlNode.SelectSingleNode always returns same value even though the node changes 为什么对象的值会改变,即使它有不同的引用? - Why object's value changes even though it has different references? 即使我限制了所提供索引的值,也遇到了ArgumentOutOfRange异常 - Getting ArgumentOutOfRange exception, even though I constrained the value of the supplied index 是否缓存了SqlConnection异常? 即使在两者之间进行了更改,我也遇到了相同的异常 - Is SqlConnection-exceptions cached? Im getting the same exception even though changes have been made in between 即使对象发生更改,也可以使变量中的值保持不变吗? - Is it possible to have the value in a variable stay the same, even when the object changes? 将对象从Main()传递给函数会更改对象,即使C#是按值进行的? - Passing object from Main() to function changes the object , even though C# is by value? C#列表获得相同的值 - C# List getting same value 即使宣布为公共财产损失价值 - Property losing value even though declared Public 选定索引更改后下拉列表返回第一个值 - dropdown list goes back to first value after selected index changes 如何加密文本字符串,以便每次加密字符串不同,即使值相同 - How do I encrypt a string of text so that the encrypted string is different each time even though the value is the same
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM