对于Matlab,Mod函数返回0

时间:2016-12-22 04:51:04

标签: matlab elliptic-curve

我在Matlab中输出public class UserController : Controller { private RequestManager requestManager = new RequestManager(); Mock<RequestManager> mockRepository = new Mock<RequestManager>(); Mock<UserViewModel> mockUserViewModel = new Mock<UserViewModel>(); ViewResult viewResult; // GET: User public async Task<ActionResult> Index() { List<UserViewModel> allUsers = await requestManager.GetUsers(); if(allUsers == null) { throw new HttpException(404, "No Users Found"); } return View(allUsers); } } public class UserControllerTest { public UserController controller; [OneTimeSetUp] public void InIt() { controller = new UserController(); } [Test] public async Task TestIndexWhenAllUsersNULL() { var view = await controller.Index() as ActionResult; List<mockUserViewModel> listofusermodel = new List<mockUserViewModel>(); //add some dummy data in your List so it will not getting data directly from your Database mockRepository.Setup(x => requestManager.GetUsers()).Returns(listofusermodel); Assert.That(view is ViewResult); Assert.That(view.Model is List<mockUserViewModel>); } } 函数有问题。我正在尝试为ECC double执行一些计算并添加算法。我正在从文件中读取数据并将其存储在变量中,然后执行一些操作。除了我使用mod0 temp1时,所有工作都顺利进行。但是,如果我在命令窗口(mod(X2,P))中放入存储在X2(3.0323e+153)P(1.1579e+77)中的值,我会得到正确的值。谁能帮帮我吗?以下是脚本中存在问题的部分。

mod( 3.0323e+153, 1.1579e+77)

1 个答案:

答案 0 :(得分:3)

我认为问题在于您如何初始化P。从hex2dec的文档(强调我的):

  

d = hex2dec('hex_value') hex_value 转换为其浮点整数表示。参数 hex_value 是存储为文本的十六进制整数。 如果 hex_value 的值大于flintmax返回的值的十六进制等值,则hex2dec可能无法返回完全转换。 < / p>

flintmax的值是:

>> flintmax
ans =
     9.007199254740992e+15

P的价值小一点。事实上,如果我们使用num2hex查看您初始化P的两种方式,则可以看到明显的差异:

>> P = hex2dec('FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F');
>> num2hex(P)
ans =
4ff0000000000000
>> num2hex(1.1579e+77)
ans =
4fefffda293c30de

事实证明,由hex2dec完成的不精确转换会产生一个均匀分为3.0323e+153的数字,从而得到0的余数:

>> mod(3.0323e+153, P)
ans =
     0
>> mod(3.0323e+153, 1.1579e+77)
ans =
     8.795697942083107e+76