编写解密密钥的代码。 [英] Writing a code for decryption key.

查看:143
本文介绍了编写解密密钥的代码。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下表达式来计算公钥加密系统中的解密密钥:



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...


这篇关于编写解密密钥的代码。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆