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

推荐订阅源

博客园 - 【当耐特】
罗磊的独立博客
J
Java Code Geeks
博客园_首页
量子位
腾讯CDC
阮一峰的网络日志
阮一峰的网络日志
Jina AI
Jina AI
WordPress大学
WordPress大学
宝玉的分享
宝玉的分享
人人都是产品经理
人人都是产品经理
博客园 - 叶小钗
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Security Latest
Security Latest
Cloudbric
Cloudbric
Last Week in AI
Last Week in AI
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - 聂微东
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
C
CXSECURITY Database RSS Feed - CXSecurity.com
IT之家
IT之家
雷峰网
雷峰网
Apple Machine Learning Research
Apple Machine Learning Research
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
C
Cybersecurity and Infrastructure Security Agency CISA
L
Lohrmann on Cybersecurity
爱范儿
爱范儿
月光博客
月光博客
Spread Privacy
Spread Privacy
T
Tailwind CSS Blog
C
CERT Recently Published Vulnerability Notes
S
Schneier on Security
V
Vulnerabilities – Threatpost
Cisco Talos Blog
Cisco Talos Blog
美团技术团队
Simon Willison's Weblog
Simon Willison's Weblog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
博客园 - 司徒正美
The Cloudflare Blog
G
GRAHAM CLULEY
I
Intezer
博客园 - 三生石上(FineUI控件)
有赞技术团队
有赞技术团队
P
Privacy International News Feed
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Hugging Face - Blog
Hugging Face - Blog
大猫的无限游戏
大猫的无限游戏
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
P
Privacy & Cybersecurity Law Blog
Engineering at Meta
Engineering at Meta

博客园 - 心有

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 }