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

推荐订阅源

Latest news
Latest news
T
Troy Hunt's Blog
V
Vulnerabilities – Threatpost
L
LINUX DO - 热门话题
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Simon Willison's Weblog
Simon Willison's Weblog
V
V2EX
博客园 - 司徒正美
B
Blog RSS Feed
AWS News Blog
AWS News Blog
MyScale Blog
MyScale Blog
Scott Helme
Scott Helme
Cisco Talos Blog
Cisco Talos Blog
Last Week in AI
Last Week in AI
NISL@THU
NISL@THU
博客园 - Franky
P
Proofpoint News Feed
博客园_首页
C
CERT Recently Published Vulnerability Notes
雷峰网
雷峰网
S
Schneier on Security
P
Proofpoint News Feed
Hugging Face - Blog
Hugging Face - Blog
G
GRAHAM CLULEY
博客园 - 三生石上(FineUI控件)
月光博客
月光博客
WordPress大学
WordPress大学
The Hacker News
The Hacker News
T
Threatpost
阮一峰的网络日志
阮一峰的网络日志
A
Arctic Wolf
Microsoft Azure Blog
Microsoft Azure Blog
T
The Exploit Database - CXSecurity.com
Engineering at Meta
Engineering at Meta
罗磊的独立博客
T
The Blog of Author Tim Ferriss
D
Darknet – Hacking Tools, Hacker News & Cyber Security
I
Intezer
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
K
Kaspersky official blog
SecWiki News
SecWiki News
云风的 BLOG
云风的 BLOG
美团技术团队
C
Cybersecurity and Infrastructure Security Agency CISA
博客园 - 【当耐特】
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Security Latest
Security Latest
C
Cyber Attacks, Cyber Crime and Cyber Security
B
Blog
S
Security Affairs

博客园 - 心有

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 }