⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rsacryptosystem.h

📁 C++ implementaion for RSA together with the Wiener attack. It uses NTL library for big numbers
💻 H
字号:
#pragma once
#pragma comment (lib, "D:/+info+/Libraries/NTL/Debug/NTL.lib")

#include "NTL/ZZ.h"
#include <string>
#include <fstream>

class RSACryptoSystem
{
public:
	typedef struct _publicKey
	{
		NTL::ZZ N; //N = p*q
		NTL::ZZ E; // e*d congr 1 mod Phi(n) = (p-1)*(q-1); e is ususly small but wrt d
	} PublicKey;

	typedef struct _privateKey
	{
		NTL::ZZ P; //P = prime - >512 bits
		NTL::ZZ Q; //Q = prime - >512 bits
		NTL::ZZ D; // d > (1/3)*n^(1/4); d from Z*_Phi(N) = (p - 1)*(q - 1)
	} PrivateKey;

private:
	PublicKey m_publicKey;
	PrivateKey m_privateKey;

private:
	long m_lBitsNr; // > 512
	
private:
	void GenerateKeys();

	void LoadKeys(std::string publicKeyFile,std::string privateKeyFile);
public:
	RSACryptoSystem(std::string privateKeyFile = "", std::string publicKeyFile = "",long bitsNr = 0);
	~RSACryptoSystem(void);

public:
	PublicKey GetPublicKey() const;
public:
	// Encode number x with public key (n,e);
	// The result will be put in y;
	void Encode(const NTL::ZZ& x, NTL::ZZ& y, const PublicKey& key);
	// Decode y with my private key (m_zzP, m_zzQ, m_zzD)
	// The result will be put in x
	void Decode(const NTL::ZZ&y, NTL::ZZ& x);
};

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -