简体   繁体   English

VB.NET处理大整数

[英]VB.NET Dealing with large integers

So I am making a file crypter so that I can encrypt my VB.NET Application that I am making so that people can't decompile it. 因此,我正在制作一个文件加密器,以便可以对自己制作的VB.NET应用程序进行加密,以使人们无法对其进行反编译。 I had made this in C# and am transfering it to VB.NET, Everything worked fine in C# but once I had re-written the code in VB.NET i get this error inside of my RC4 Encryption method: 我已经在C#中完成了此任务,并将其传输到VB.NET,在C#中一切正常,但是一旦我在VB.NET中重新编写了代码,我便在RC4加密方法中收到此错误:

'Arithmetic operation resulted in an overflow.'

The error is occuring here: 错误发生在这里:

Dim t As Int64 = (s(i) + s(j)) Mod 256

This is the same code above in c#: 这与上面的c#中的代码相同:

int t = (s[i] + s[j]) % 256;

Is there anyway to make that calculation with it erroring? 反正有错误进行该计算吗? And why does it work in C# but not VB.NET? 为何它不能在C#中工作但不能在VB.NET中工作?

Check your advanced compile options in the VB.NET project (project properties -> Compile -> Advanced Compile Options...). 检查VB.NET项目中的高级编译选项(项目属性->编译->高级编译选项...)。 Compare with your C# project. 与您的C#项目进行比较。 The VB version may be checking for integer overflows, and the C# version not. VB版本可能正在检查整数溢出,而C#版本不是。

When I run a test in VB, this code generates the exception: 当我在VB中运行测试时,此代码会生成异常:

Dim x As Int16 = Int16.MaxValue
Dim y As Int16 = Int16.MaxValue

Dim t As Int64 = (x + y) Mod 256

But this code does not: 但是此代码不会:

Dim t As Int64 = (32767 + 32767) Mod 256

If I turn off overflow checking, both sets of code complete without error. 如果我关闭溢出检查,则两组代码均会完整无误。

Check values of each variable in the equation to see if there might be an overflow occurring based upon the addition part. 检查等式中每个变量的值,以查看是否存在基于加法部分的溢出。 The datatype of the result of the addition operation is based upon the datatypes of the variables/values involved in the operation. 加法运算结果的数据类型基于运算中涉及的变量/值的数据类型。 Those values may be yielding a result too large for the derived datatype. 对于派生的数据类型,这些值可能会产生太大的结果。

In .Net 4.0 there is a new type called BigInteger: http://msdn.microsoft.com/en-us/library/system.numerics.biginteger.aspx 在.Net 4.0中,有一个称为BigInteger的新类型: http : //msdn.microsoft.com/zh-cn/library/system.numerics.biginteger.aspx

Although I think the solution you really want is to obfuscate your code so even if someone decompiles they wont be able to read it: Visual Studio > Tools Menu > Dotfuscator 尽管我认为您真正想要的解决方案是混淆代码,所以即使有人进行反编译,他们也将无法阅读它:Visual Studio>工具菜单> Dotfuscator

If you want to completely protect your code your going to have to pay for something like Remotesoft's Salamander 如果您想完全保护您的代码,则必须支付Remotesoft的Salamander之类的费用

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM