资源简介
毕业设计-RSA算法(源代码+论文+ppt)
包括rsa算法源代码和论文
代码片段和文件信息
#include “stdafx.h“
// This is a draft version of RSA encryption
// Improved by sanicle2006.1
// 3mn@3mn.net
#include “rsa_draft.h“
class prime_factory
{
unsigned np;
unsigned *pl;
public:
prime_factory();
~prime_factory();
vlong find_prime( vlong & start );
};
// prime factory implementation
static int is_probable_prime( const vlong &p )
{
// Test based on Fermats theorem a**(p-1) = 1 mod p for prime p
// For 1000 bit numbers this can take quite a while
const rep = 4;
const unsigned any[rep] = { 2357 };
for ( unsigned i=0; i if ( modexp( any[i] p-vlong(1) p ) != vlong(1) )
return 0;
return 1;
}
prime_factory::prime_factory()
{
np = 0;
unsigned NP = 200;
pl = new unsigned[NP];
// Initialise pl
unsigned SS = 8*NP; // Rough estimate to fill pl
char * b = new char[SS+1]; // one extra to stop search
for (unsigned i=0;i<=SS;i+=1) b[i] = 1;
unsigned p = 2;
while (1)
{
// skip composites
while ( b[p] == 0 ) p += 1;
if ( p == SS ) break;
pl[np] = p;
np += 1;
if ( np == NP ) break;
// cross off multiples
unsigned c = p*2;
while ( c < SS )
{
b[c] = 0;
c += p;
}
p += 1;
}
delete [] b;
}
prime_factory::~prime_factory()
{
delete [] pl;
}
vlong prime_factory::find_prime( vlong & start )
{
unsigned SS = 1000; // should be enough unless we are unlucky
char * b = new char[SS]; // bitset of candidate primes
unsigned tested = 0;
while (1)
{
unsigned i;
for (i=0;i b[i] = 1;
for (i=0;i {
unsigned p = pl[i];
unsigned r = start % vlong(p); // not as fast as it should be - could do with special routine
if (r) r = p - r;
// cross off multiples of p
while ( r < SS )
{
b[r] = 0;
r += p;
}
}
// now test candidates
for (i=0;i {
if ( b[i] )
{
tested += 1;
if ( is_probable_prime(start) )
return start;
}
start += 1;
}
}
delete [] b;
}
static vlong from_str( const char * s )
{
vlong x = 0;
while (*s)
{
x = x * vlong(256) + vlong((unsigned char)*s);
s += 1;
}
return x;
}
void private_key::create( const char * r1 const char * r2 )
{
// Choose primes
{
prime_factory pf;
p = pf.find_prime( from_str(r1) );
q = pf.find_prime( from_str(r2) );
if ( p > q ) { vlong tmp = p; p = q; q = tmp; }
}
// Calculate public key
{
m = p*q;
e = 50001; // must be odd since p-1 and q-1 are even
while ( gcd(p-vlong(1)e) != vlong(1) || gcd(q-vlong(1)e) != vlong(1) ) e += 2;
}
}
vlong public_key::encrypt( const vlong& plain )
{
return modexp( plain e m );
}
vlong private_key::decrypt( const vlong& cipher )
{
// Calculate values for performing decryption
// These coul
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 486400 2007-06-08 10:54 毕业设计-RSA算法(源代码+论文+ppt)\RSA加密毕业论文说明书.doc
文件 585728 2007-06-12 07:49 毕业设计-RSA算法(源代码+论文+ppt)\RSA文件加密的研究和实现6.8.ppt
文件 33540 2005-02-28 18:35 毕业设计-RSA算法(源代码+论文+ppt)\sanpack_rsa_vs2003sln_src_20060613\1.jpg
文件 22321 2006-03-14 15:32 毕业设计-RSA算法(源代码+论文+ppt)\sanpack_rsa_vs2003sln_src_20060613\3380461.jpg
文件 15588 2007-06-08 21:06 毕业设计-RSA算法(源代码+论文+ppt)\sanpack_rsa_vs2003sln_src_20060613\clip_image002.jpg
文件 46802 2006-06-13 15:08 毕业设计-RSA算法(源代码+论文+ppt)\sanpack_rsa_vs2003sln_src_20060613\sanpack_rsa.jpg
文件 134144 2007-06-12 08:02 毕业设计-RSA算法(源代码+论文+ppt)\sanpack_rsa_vs2003sln_src_20060613\sanpack_rsa.ncb
文件 2182 2006-01-23 12:02 毕业设计-RSA算法(源代码+论文+ppt)\sanpack_rsa_vs2003sln_src_20060613\sanpack_rsa.sln
..A..H. 20480 2007-06-12 08:02 毕业设计-RSA算法(源代码+论文+ppt)\sanpack_rsa_vs2003sln_src_20060613\sanpack_rsa.suo
文件 830 2007-06-12 07:51 毕业设计-RSA算法(源代码+论文+ppt)\sanpack_rsa_vs2003sln_src_20060613\sanpack_rsa_c_dll\Debug\BuildLog.htm
文件 33442 2007-06-12 07:50 毕业设计-RSA算法(源代码+论文+ppt)\sanpack_rsa_vs2003sln_src_20060613\sanpack_rsa_c_dll\Debug\rsa_draft.obj
文件 87716 2007-06-12 07:50 毕业设计-RSA算法(源代码+论文+ppt)\sanpack_rsa_vs2003sln_src_20060613\sanpack_rsa_c_dll\Debug\rsa_san.obj
文件 19770 2007-06-12 07:50 毕业设计-RSA算法(源代码+论文+ppt)\sanpack_rsa_vs2003sln_src_20060613\sanpack_rsa_c_dll\Debug\sanpack_rsa.obj
目录 0 2008-09-02 14:40 毕业设计-RSA算法(源代码+论文+ppt)\sanpack_rsa_vs2003sln_src_20060613\sanpack_rsa_c_dll\Debug
文件 1003 2006-01-18 12:31 毕业设计-RSA算法(源代码+论文+ppt)\sanpack_rsa_vs2003sln_src_20060613\sanpack_rsa_c_dll\ReadMe.txt
文件 3380 2006-01-18 23:20 毕业设计-RSA算法(源代码+论文+ppt)\sanpack_rsa_vs2003sln_src_20060613\sanpack_rsa_c_dll\rsa_draft.cpp
文件 522 2006-01-18 23:21 毕业设计-RSA算法(源代码+论文+ppt)\sanpack_rsa_vs2003sln_src_20060613\sanpack_rsa_c_dll\rsa_draft.h
文件 9591 2006-05-15 14:02 毕业设计-RSA算法(源代码+论文+ppt)\sanpack_rsa_vs2003sln_src_20060613\sanpack_rsa_c_dll\rsa_san.cpp
文件 1217 2006-05-15 14:01 毕业设计-RSA算法(源代码+论文+ppt)\sanpack_rsa_vs2003sln_src_20060613\sanpack_rsa_c_dll\rsa_san.h
文件 3024 2007-06-08 20:57 毕业设计-RSA算法(源代码+论文+ppt)\sanpack_rsa_vs2003sln_src_20060613\sanpack_rsa_c_dll\sanpack_rsa.cpp
文件 1626 2006-05-15 13:34 毕业设计-RSA算法(源代码+论文+ppt)\sanpack_rsa_vs2003sln_src_20060613\sanpack_rsa_c_dll\sanpack_rsa.h
文件 3804160 2006-01-18 15:50 毕业设计-RSA算法(源代码+论文+ppt)\sanpack_rsa_vs2003sln_src_20060613\sanpack_rsa_c_dll\sanpack_rsa.ncb
..A..H. 15360 2006-01-18 15:50 毕业设计-RSA算法(源代码+论文+ppt)\sanpack_rsa_vs2003sln_src_20060613\sanpack_rsa_c_dll\sanpack_rsa.suo
文件 4428 2006-01-23 12:11 毕业设计-RSA算法(源代码+论文+ppt)\sanpack_rsa_vs2003sln_src_20060613\sanpack_rsa_c_dll\sanpack_rsa.vcproj
文件 215 2006-01-18 12:31 毕业设计-RSA算法(源代码+论文+ppt)\sanpack_rsa_vs2003sln_src_20060613\sanpack_rsa_c_dll\stdafx.cpp
文件 263 2006-01-18 12:31 毕业设计-RSA算法(源代码+论文+ppt)\sanpack_rsa_vs2003sln_src_20060613\sanpack_rsa_c_dll\stdafx.h
文件 10815 2006-01-19 13:38 毕业设计-RSA算法(源代码+论文+ppt)\sanpack_rsa_vs2003sln_src_20060613\sanpack_rsa_c_dll\vlong.cpp
文件 1782 2006-01-19 13:37 毕业设计-RSA算法(源代码+论文+ppt)\sanpack_rsa_vs2003sln_src_20060613\sanpack_rsa_c_dll\vlong.h
目录 0 2008-09-02 14:40 毕业设计-RSA算法(源代码+论文+ppt)\sanpack_rsa_vs2003sln_src_20060613\sanpack_rsa_c_dll
文件 4530 2007-06-08 22:07 毕业设计-RSA算法(源代码+论文+ppt)\sanpack_rsa_vs2003sln_src_20060613\sanpack_rsa_dotnet11\about.cs
............此处省略56个文件信息
评论
共有 条评论