[英]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) 链接到项目(这是一个程序,因此代码本身不起作用)
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.