编写解密密钥的代码。

编程入门 行业动态 更新时间:2024-10-25 04:14:44
本文介绍了编写解密密钥的代码。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有以下表达式来计算公钥加密系统中的解密密钥: d = N -1 mod LCM(p-1,q-1) 其中 N = p 2 q 。 我写了以下代码来找到d,

I have the following expression for calculating the decryption key in a Public Key Encryption System : d = N-1 mod LCM(p-1,q-1) where N = p2q. I wrote the follwing code to find d ,

long long int gendecrypkey(long long int modulo,long long int p,long long int q) { long long int dk = 0; while(!(dk * modulo == fmod(1,lcm((p-1),(q-1))))) { ++dk ; } return dk; }

但这是找到d的正确方法吗?如果不是,请建议用于查找d的C ++代码。 执行此功能时,控制台不会显示任何内容(空白)。可能是什么错误? [更新]

but is this the right way of finding d ? If not please suggest a C++ code for finding d. Upon execution of this function the console wont show anything (blank).What could be the mistake? [updated]

sscrypto(long long int &publkey, long long int &privtkey,long long int &pq) { publickey = publkey =0; privatekey = privtkey = 0; long long int p = genrndprimes(50,200); long long int q = genrndprimes(200,300); long long int n = (p*p)*q; //Modulus. long long int d = fmod((1/n),lcm(p-1,q-1)); //Problematic code pq = p*q; publkey = publickey = n; privtkey = privatekey = d; }

推荐答案

不是吗 Wouldn't it be fmod((1/(p*p*q)), lcm((p-1), (q-1)))

? 另外,你得到一个空白屏幕,因为你的while循环永远不会收敛,所以你陷入无限循环。我也不确定基于你提供的信息的模数值是什么,所以我无法真正告诉你这部分是对还是错......

? Also, you are getting a blank screen because your while loop never converges, so you are stuck in an infinite loop. I'm also not sure what the "modulo" value is based on the information you gave, so I can't really tell you if that part is right or wrong...

更多推荐

编写解密密钥的代码。

本文发布于:2023-11-13 01:42:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1583064.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:密钥   代码

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!