惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Secure Thoughts
S
Securelist
T
The Exploit Database - CXSecurity.com
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Schneier on Security
Schneier on Security
P
Proofpoint News Feed
Latest news
Latest news
C
CXSECURITY Database RSS Feed - CXSecurity.com
Google DeepMind News
Google DeepMind News
Microsoft Security Blog
Microsoft Security Blog
美团技术团队
T
Threat Research - Cisco Blogs
Know Your Adversary
Know Your Adversary
AWS News Blog
AWS News Blog
V2EX - 技术
V2EX - 技术
云风的 BLOG
云风的 BLOG
博客园 - 聂微东
腾讯CDC
月光博客
月光博客
G
Google Developers Blog
F
Fortinet All Blogs
C
Cybersecurity and Infrastructure Security Agency CISA
Hacker News - Newest:
Hacker News - Newest: "LLM"
阮一峰的网络日志
阮一峰的网络日志
Last Week in AI
Last Week in AI
Apple Machine Learning Research
Apple Machine Learning Research
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
爱范儿
爱范儿
WordPress大学
WordPress大学
Spread Privacy
Spread Privacy
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
T
Threatpost
N
News and Events Feed by Topic
Y
Y Combinator Blog
J
Java Code Geeks
N
News and Events Feed by Topic
T
Troy Hunt's Blog
Project Zero
Project Zero
博客园 - 【当耐特】
Microsoft Azure Blog
Microsoft Azure Blog
C
CERT Recently Published Vulnerability Notes
小众软件
小众软件
有赞技术团队
有赞技术团队
罗磊的独立博客
Martin Fowler
Martin Fowler
L
LINUX DO - 最新话题
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
www.infosecurity-magazine.com
www.infosecurity-magazine.com
P
Proofpoint News Feed

博客园 - 心有

go语言最好的帮助在哪里? go语言的init函数 我的go语言上机测试代码 解决golang.org不能访问的问题 win7下安装32位GoSublime Package oracle和sybase的帮助文档 用bat文件设置程序启动环境 go语言 windows 32位编译环境搭建 Go没有枚举类型(enums),用const常量的iota替代 oracle数据库性能优化 - 降低IO c#长字符串显示省略号 - 心有 - 博客园 C#的timer类问题~! 计划任务工具 cron 的配置和说明 TRACERT命令及用法 linux下挂载windows的共享文件目录ftp文件夹到/root/wind目录 Linux 用户(user)和用户组(group)管理概述 Linux用户和用户组的管理概述 用NetTerm连接虚拟机的telnet服务,打造轻松自如的虚拟机实验环境 请高人指点下,手机震动时从平台上掉入水中,是用户使用不当还是手机设计缺陷,维修费用由谁承担?
c语言中的大数运算模块
心有 · 2012-05-13 · via 博客园 - 心有

  随着计算机系统的快速发展,经常需要对海量数据和信息做处理,在处理这些数据时经常会遇到很大的数字,无法用int或者long等类型来存储,经常看到有人自己在写或者讨论大数相关的问题,本文描述从开源库polarssl中提取的大数bignum模块,独立出来集成到应用程序中的方法,该模块支持的大数位数不限制。

  摘取出来的模块仅仅包含:bignum.c、bignum.h、bn_mul.h三个文件,简单易用。

  相关代码和测试代码如下:

 /Files/youyou/bignum.rar

 1 #include <string.h>
 2 #include <stdio.h>
 3 
 4 #include "bignum.h"
 5 
 6 void test_add_mul()
 7 {
 8 /*
 9 //test result:
10     A = 123456789012345678901234567890
11     B = 123456789012345678901234567890
12     X = A + B
13     X = 246913578024691357802469135780
14 
15     A = 123456789012345678901234567890
16     B = 123456789012345678901234567890
17     X = A * B
18     X = 15241578753238836750495351562536198787501905199875019052100
19   
20     press any key to contiue ...
21 */
22     int ret, temp;
23     mpi A, B, X;
24     size_t n;
25     char a[ 2 * POLARSSL_MPI_MAX_SIZE + 2 ];
26     char b[ 2 * POLARSSL_MPI_MAX_SIZE + 2 ];
27     char x[ 2 * POLARSSL_MPI_MAX_SIZE + 2 ];
28 
29     n = sizeof(a);
30     temp = n - 2;    
31         
32     mpi_init( &A ); mpi_init( &B ); mpi_init( &X );
33     
34     MPI_CHK( mpi_read_string( &A, 10,
35         "123456789012345678901234567890") );
36     
37     MPI_CHK( mpi_read_string( &B, 10,
38         "123456789012345678901234567890") );
39     
40     MPI_CHK( mpi_add_mpi( &X, &A, &B ) );
41 
42     memset( a, 0sizeof(a) );
43     memset( b, 0sizeof(b) );
44     memset( x, 0sizeof(x) );
45     n = temp;
46     MPI_CHK( mpi_write_string( &A, 10, a, (size_t *) &n ) );    
47     n = temp;
48     MPI_CHK( mpi_write_string( &B, 10, b, (size_t *) &n ) );    
49     n = temp;
50     MPI_CHK( mpi_write_string( &X, 10, x, (size_t *) &n ) );    
51     printf("A = %s\n", a);
52     printf("B = %s\n", b);
53     printf("X = A + B\n");
54     printf("X = %s\n", x);
55     printf("\n");
56 
57     MPI_CHK( mpi_mul_mpi( &X, &A, &B ) );
58     
59     memset( a, 0sizeof(a) );
60     memset( b, 0sizeof(b) );
61     memset( x, 0sizeof(x) );
62     n = temp;
63     MPI_CHK( mpi_write_string( &A, 10, a, (size_t *) &n ) );    
64     n = temp;
65     MPI_CHK( mpi_write_string( &B, 10, b, (size_t *) &n ) );    
66     n = temp;
67     MPI_CHK( mpi_write_string( &X, 10, x, (size_t *) &n ) );    
68     printf("A = %s\n", a);
69     printf("B = %s\n", b);
70     printf("X = A * B\n");
71     printf("X = %s\n", x);
72     printf("\n");
73         
74 cleanup:
75     
76     mpi_free( &A ); mpi_free( &B ); mpi_free( &X );
77 }
78 
79 void my_pause()
80 {
81     printf("press any key to contiue ...");
82     getchar();
83 }
84 
85 int main( int argc, char *argv[] )
86 {
87 
88     test_add_mul();
89 
90     my_pause();
91 
92     return 0;

93 }